javascript how to check type code example
Example 1: check type string javascript
if (typeof myVar === 'string' || myVar instanceof String)
else
Example 2: check type javascript
console.log(typeof "how are you?")
"string"
console.log(typeof false) / console.log(typeof true)
"boolean"
console.log(typeof 100)
"number"
Example 3: type of javascript
if (typeof(value) !== "undefined") {
}
Example 4: javascript check if variable is object
function isObject(val) {
if (val === null) { return false;}
return ( (typeof val === 'function') || (typeof val === 'object') );
}
var person = {"name":"Boby Snark"};
isObject(person);
Example 5: check data type in js
var x = "Hello World";
typeof x;