|
|
|
|
|
by xupybd
4367 days ago
|
|
So it's Not-a-Number but isNumber returns true? That would imply then that isNumber is named incorrectly. So perhaps isNumber should read isNumericType? Most of the time I want to test, is this a number I can use in a normal mathematical sense. As in, can I use it in subtraction, multiplication etc. I know now that I should use isFinite and isNumber, but wouldn't it be nice to have just one well named function for this? |
|
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".