get type ov value js code example
Example 1: javascript how to know type of variable
var foo = "Hello";
console.log(typeof foo); // string
Example 2: get type of var js
function doSomething(x) {
if(typeof(x) === 'string') {
alert('x is a string')
} else if(typeof(x) === 'number') {
alert('x is a number')
}
}