Everything in JS is an object. I've always known that, and I totally understand that. I know why {} !== {}
. It's two different objects. Same as if you were to write out new Object() == new Object()
.
Some other examples:
{} == {} // => false
[] == [] // => false
/ / == / / // => false
new String() == new String() // => false
But, Strings are objects too (it's why you can do ''.replace()
and extend them), so why does this work:
'' == '' // => true
Obviously it'd be a huge headache to compare two strings if this didn't work, but this seems inconsistent with the rest of the language. Internally, what's going on? Is it just a one-off or is there some other concept behind this?