The answer is simple: NaN
is a number.
The term "not a number" doesn't mean "not a member of the type number
in JavaScript". It's a term from the relevant floating-point specification, in which a set of bit patterns is collectively used to designate values that are "not numbers"; that is, the bit patterns are not valid.
It's somewhat unfortunate that JavaScript was designed such that certain operations that have numerically meaningless results yield NaN
, since the point of NaN
in the spec is to designate values to be avoided. It's too late to revisit that decision however.
The global isNaN()
function always attempts to convert its argument to number
before performing the test. Thus, it's often used to check if a string value contains digits that can be interpreted as a valid number.