Question

As it says in the question really, I tried value == NaN and it was false and then remembered that I should be using isNaN(value) to check for this.

Why the difference?

Was it helpful?

Solution

both NaN == NaN and NaN === NaN evaluate to false as from MDN

NaN is a special value which you can think of as for example Infinity. Infinity is not equal to another Infinity as it has NO DEFINED VALUE.

OTHER TIPS

I can't put it any better than MDN do so...

Unlike all other possible values in JavaScript, it is not possible to rely on the equality operators (== and ===) to determine whether a value is NaN or not, because both NaN == NaN and NaN === NaN evaluate to false. Hence, the necessity of an isNaN function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top