DEV Community

loading...
Cover image for Explain typeof operator in Javascript with example

Explain typeof operator in Javascript with example

srijan82239366 profile image Srijan Originally published at hackinbits.com ・1 min read

This post first appeared on hackinbits.com

The typeof operator helps in finding the type of value that your variable is storing. It returns a string indicating the type of argument. It supports two syntaxes:

  1. As an operator: typeof v.
  2. As a function: typeof (v).

Example:

var exp = typeof "Welcome to hackinbits.com";

//output: "string".
console.log(exp)

You can also use typeof operator to check whether a value is undefined or not.

let testVar = undefined;
var typeVar = typeof testVar;

//output: "undefined".
console.log(typeVar)

Related Article

Discussion (0)

pic
Editor guide