Monday, June 17, 2019

JavaScript | JQuery | Check if a variable is type of String | Number | Null | Undefined | Array | Object

console.log(Object.prototype.toString.call("This is string"));
console.log(Object.prototype.toString.call(undefined));
console.log(Object.prototype.toString.call(0));
console.log(Object.prototype.toString.call(null));
console.log(Object.prototype.toString.call([]));
console.log(Object.prototype.toString.call({}));
And respective output is as below:
[object String]
[object Undefined]
[object Number]
[object Null]
[object Array]
[object Object]

No comments:

Post a Comment