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?
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?
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.
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 isNaN
or not, because bothNaN == NaN
andNaN === NaN
evaluate tofalse
. Hence, the necessity of anisNaN
function.