Is there a way for typeof to return what an object is?
typeof {};
returns "object"
typeof [];
also returns "object". Is there a way in js to return "array"?
On top of that, is there a way to tell if an object is a DOM object, a javascript object or whatever object?
You can't extend the typeof
operator but for better type inspection you can (ab)use Object.prototype.toString
Object.prototype.toString.call([]) === '[object Array]'
Object.prototype.toString.call(document) === '[object HTMLDocument]`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With