To check what the real type of and variable, run this command:
Object.prototype.toString.call(myVar)
It'll return something like [object Object]
. The second word is the real type of the variable.
Some examples:
console.log(Object.prototype.toString.call(null)) // returns [object Null]
console.log(Object.prototype.toString.call(undefined)) // returns [object Undefined]
console.log(Object.prototype.toString.call([])) // returns [object Array]
console.log(Object.prototype.toString.call(new Date())) // returns [object Date]
console.log(Object.prototype.toString.call({})) // returns [object Object]
console.log(Object.prototype.toString.call(new Error('error'))) // returns [object Error]
console.log(Object.prototype.toString.call(/\D/)) // returns [object RegExp]
// ... and so on...
To check if a variable is an object, you can use something like:
if(Object.prototype.toString.call(myVar).endsWith('Object]')) {
// do something
}