Explain typeof operator in Javascript with example.


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).


var exp = typeof "Welcome to hackinbits.com";
//output: "string".

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

testVar = undefined;
var typeVar = typeof testVar;
//output: "undefined".

Related Article: Javascript Data Types Explained

Share and support us

Share on social media and help us reach more people