DEV Community

Discussion on: The Lies of "===" operator

Collapse
 
lexlohr profile image
Alex Lohr

Actually, both are valid cases, since === compares the actual value and not the reference. Since primitives that contain the exact same value are stored within the same reference, Object.is will work; the value of 0 and -0 is the same, but since the sign differs, they are stored with different references.

And NaN is specifically meant not to work as a number, so it should not be calculatable or comparable - so if you put garbage into JS numbers, you'll get garbage out, even if you add non-garbage numbers. Object.is will work again here, because the reference to both instances of NaN is still the same.

So it's not a lie, even though the result might be unexpected if you are not familiar with the spec of the language.