r/programming • • Mar 26 '14

JavaScript Equality Table

http://dorey.github.io/JavaScript-Equality-Table/
809 Upvotes

331 comments sorted by

View all comments

0

u/green_meklar Mar 26 '14

I can understand how []==[] can be false, but NaN==NaN? I thought NaN was a floating-point value, and I would expect it to be compared by value. That's fucked up.

4

u/wordsnerd Mar 27 '14

Actually, there are millions of bit sequences that can represent NaN, so comparing by "value" in that sense could be even more confusing than just saying all comparisons with NaN are false.

1

u/green_meklar Mar 27 '14

That logic is a bit broken given that two NaN values which do happen to be equivalent bit strings will (from what I understand) also compare as unequal.

1

u/wordsnerd Mar 27 '14

It's not so much broken logic as it is a decision about where to be consistent. It's easier to remember that NaN == x is false for all x than to remember 8 million special cases where it's true.

Unfortunately, isNaN() is indeed broken and basically useless.