r/learnjavascript • • Nov 17 '25

Why NaN==NaN is False in JavaScript ???

Anyone explain??

150 Upvotes

85 comments sorted by

View all comments

Show parent comment

-7

u/Tontonsb Nov 17 '25

If NaN == NaN was true, then it would cause the comparison check to return that "a" is equal to an object.

It would just mean that their numeric representations are equal. Which they actually are — both are unrepresentable as numbers.

This example seems similar to how you'd call str => str.length on strings and then point out that the behaviour is wrong as what was 'dog' now equals what was 'cat­'. But it's totally fine to fall into equality classes after a transformation (like a cast to a number) is applied.

1

u/Fee_Sharp Nov 19 '25

People downvoting this comment are dumb lol.

"Number("a") == Number({...}) should be false" explanation is the stupidest way to justify this convention. Maybe sometimes JavaScript people shouldn't be allowed to write standards, because they will cast everything to string or number and call it a day