how to check object type in javascript code example
Example 1: javascript check if variable is object
//checks if is object, null val returns false
function isObject(val) {
if (val === null) { return false;}
return ( (typeof val === 'function') || (typeof val === 'object') );
}
var person = {"name":"Boby Snark"};
isObject(person);//true
Example 2: how to get type of variable in javascript
> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"