The first thing that isNaN()
does is convert its parameter to a number (as you yourself wrote). If the parameter is an object, that's done by calling the .valueOf()
method of the object. In the case of Date instances that returns the timestamp, and it won't be NaN
for any valid Date.
Try this:
alert(isNaN({ valueOf: function() { return 12; } }));
And for an invalid date:
alert(isNaN(new Date("potatoes")));
That'll be true
. If you want a stricter isNaN
you can use Number.isNaN
:
alert(Number.isNaN(NaN)); // true
The version of isNaN
on the Number constructor won't coerce its argument to a number; it's job is to say whether the thing you pass in is the NaN
value, without any type casting. So by that function, there's one and only one NaN
.