Hacker News new | ask | show | jobs
by dragonwriter 4367 days ago
> 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".

1 comments

We just need a way to indicate if the method is checking the type or the value.