News for hackers. Stuff that matters.
Re:WTFJS – a list of funny and tricky JavaScript examples by roywiggins on Monday July 31, 2017 @09:35AM (#14891785)
That's just normal floating point behavior. NaN isn't equal to anything, not even itself. It's in the standard.
Re:WTFJS – a list of funny and tricky JavaScript examples by tambourine_man on Monday July 31, 2017 @10:09AM (#14892103)
Floating point can be a bit mind bending. Still, something not being equal to itself almost pushes the barrier into philosophy.
Re:WTFJS – a list of funny and tricky JavaScript examples by roywiggins on Monday July 31, 2017 @01:30PM (#14894106)
As long as you can define what's going on rigorously, it's just mathematics :) The equality operator means just what I choose it to mean- neither more nor less, as Humpty Dumpty would say.

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.

Re:WTFJS – a list of funny and tricky JavaScript examples by fmihaila on Monday July 31, 2017 @10:54AM (#14892532)
NaN is not a name for one thing. You could think of not a number as not any particular thing. There is no comparison with itself, because there is no it.
Re:WTFJS – a list of funny and tricky JavaScript examples by goatlover on Monday July 31, 2017 @11:02AM (#14892625)
How is isNaN() implemented?
Re:WTFJS – a list of funny and tricky JavaScript examples by Gaelan on Monday July 31, 2017 @11:21AM (#14892804)

    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.
Re:WTFJS – a list of funny and tricky JavaScript examples by tambourine_man on Monday July 31, 2017 @11:37AM (#14892940)
We really are deep in the realm of Philosophy.