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:
- As an operator: typeof v.
- 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)
Top comments (0)