Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top