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