Oh yeah! I like this topic, already. Let's geek the **** out! :neckbeard:
I think it's important to mention, that I'm fiddling in Chrome. Which is always a good idea, when trying code for nodeJS. Both use V8. Safari, FireFox, etc. might behave differently!
(0 == '') === true
could be, because JS does type conversion there. I doubt that the function is internally used, but the underlying C might be the same, due to DRY. Anyway does
(Number('') === 0)
hold true.
Your actual question startles me a bit, too. First fiddles make me think the same - implementation hickup.
Because the objects seem the same
Object.getOwnPropertyNames([]+{})
["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "length"]
Object.getOwnPropertyNames({}+[])
["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "length"]
They seem to be both strings
typeof ({}+[])
"string"
typeof ([]+{})
"string"
I just love how Array()
doesn't allocate, but makes you believe it has:
Object.keys(new Array(7))
[]
new Array(7).length
7
Object.keys(Array.apply(null, { length: 7 }))
["0", "1", "2", "3", "4", "5", "6"]