DEV Community

Discussion on: Why NaN === NaN returns false in JavaScript ?!

Collapse
 
lexlohr profile image
Alex Lohr

This explains what NaN is, but not the reason why Brendan Eich came up with it, which is: in algebraic functions, there may be undefined results, for example Math.sqrt(-1). If one would be handling these results as undefined, they would be coerced to zero in further operations, which could lead to results that are mistaken for correct ones. Thus every mathematical operation with NaN yields NaN and comparisons always fail.