DEV Community

Discussion on: Why Is {} > [] ?

Collapse
 
amyshackles profile image
Amy Shackles

I'm honestly kind of tempted to go through the entire infamous Wat video and break down all the different parts of it.

Also, I think you read this before the most recent update that should clear up a few of the lingering questions one might have (such as "But if they're both objects, why does one evaluate to "[object Object]" and the other evaluate to an empty string? What's the heck?!"

Collapse
 
stereobooster profile image
stereobooster • Edited
// object to string
({}) instanceof Object // true
Object.prototype.toString.call({}) // "[object Object]"
([]) instanceof Array // true
Object.prototype.toString.call([]) // "[object Array]"
// "inheritance"
Array instanceof Object // true
Object instanceof Array // false
// array to string
[1,2].join(",") // "1,2"
[1,2].toString() // "1,2"
Enter fullscreen mode Exit fullscreen mode