print type of variable javascript code example
Example 1: check data type in javascript
typeof("string"); //string
typeof(123); //number
Example 2: get type of var js
var x = 12345;
console.log(typeof x) // number
x = 'string';
console.log(typeof x) // string
x = { key: 'value' };
console.log(typeof x) // object
Example 3: javascript check type of variable var
> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"