Re:NaN does not mean "I am not a number”
by dragonwriter on Thursday July 10, 2014 @08:15PM
(#8018168)
> So it's Not-a-Number but isNumber returns true?
NaN is not a number (the concept) but it is a Number (the type).
> That would imply then that isNumber is named incorrectly.
Arguably, it is Number (the type) that is named incorrectly (a type called Number that includes a value called Not-a-Number seems problematic.) Maybe "Number" should be called "MaybeNumber".
And, perhaps more importantly, the fact that JS doesn't have a convenient type membership operator for primitive types is problematic, as if there was a convenient parallel to "instanceOf" for primitive types -- or if "instanceOf" just worked for them -- then libraries wouldn't need to provide something like what underscores isNumber does at all, and then any isNumber function would probably test "is the argument a number" rather than "is the argument a Number".
NaN is not a number (the concept) but it is a Number (the type).
> That would imply then that isNumber is named incorrectly.
Arguably, it is Number (the type) that is named incorrectly (a type called Number that includes a value called Not-a-Number seems problematic.) Maybe "Number" should be called "MaybeNumber".
And, perhaps more importantly, the fact that JS doesn't have a convenient type membership operator for primitive types is problematic, as if there was a convenient parallel to "instanceOf" for primitive types -- or if "instanceOf" just worked for them -- then libraries wouldn't need to provide something like what underscores isNumber does at all, and then any isNumber function would probably test "is the argument a number" rather than "is the argument a Number".