NaN === NaN // -> false
Are pretty f*&^%$ up, no matter how you look at themEdit: well, apparently there is a non f&^%$ up way to look at it: https://news.ycombinator.com/item?id=14891810
NaN === NaN // -> false
Are pretty f*&^%$ up, no matter how you look at themEdit: well, apparently there is a non f&^%$ up way to look at it: https://news.ycombinator.com/item?id=14891810
1/0 !== 1/0
This is not a very good explanation. NaN is used to represent a nonsensical value. By your explanation (1/0 === 1/0) should be true since they represent the same invalid opperation. The fact that NaN != NaN is not meant to mean anything, it is merely defined that way to prevent a class of bugs from occurring. Anyone not familiar with the definition is correct to be confused by it. I'd think if the spec was designed today, this special case (hack) wouldn't be there and we'd have exceptions in its place.
function isNaN(x) { return x !== x }
It’s a native browser function so it may not actually be done that way, but that’s one way you could do it.Also fun: (NaN < x) should be false for every x, and (NaN > x) should be false for every x. It's not a number, so it's not less than or greater than any number. But then by process of elimination, NaN == x for every x. Which is obviously nonsense. So equality and comparison is completely "broken" anyway when you start comparing NaN to things.