« first day (3220 days earlier)      last day (38 days later) » 

12:34 AM
 
1 hour later…
1:35 AM
"NaN is a number." – @VLAZ, 2024-08-12
I dunno, I feel like it's in the name that it's not :-p
 
3 hours later…
4:12 AM
@RyanM I know, I know. I do have an explanation that tends to work, though. So, you have some value that you need to convert to a numeric and only numeric. So, you have a function that does any_value -> number conversion. However, you eventually get a value that cannot be converted, like "apple". The function doesn't throw errors, it still must produce a number. So, it can only return you something from the numeric realm signifying the result is not a number.
And then, you get NaN. Maybe the input was "apples" one time, which returns NaN. And another might have been "orange" which is also NaN. It's also why NaN != NaN - you can't compare the numeric representations of two non-numerics. After all "apple" != "orange" you can't suddenly claim they are equal after the conversion.
Maybe they could have called the value "error_ohmigod" or something. So it's doesn't sound contradictory as it does now.
 
6 hours later…
10:17 AM
Also, in researching whether JavaScript has a concept of "numeric", I found this trash fire of a question, which asks in the title, how to "Check that variable is a number", but then defines "a number" as "either an integer or a string digit" in the body.
Naturally, the top answer is ...just totally wrong? It correctly answers neither question, suggesting isNaN (which, presumably, one would need to invert), which would find such things as booleans, the string "Infinity", the empty string, and a space to be numeric.
The accepted answer, which has fewer votes, fixes...most of that, only failing on whitespace strings (assuming the question is the one in the title, not the body, though they link to a separate answer for that).
The trending answer says how to tell if a variable is a number that is an integer (and not, say, a string digit).
10:33 AM
Then there's the apparent canonical, Validate decimal numbers in JavaScript - IsNumeric(), which has a beautifully tested answer with nearly 3k net score ... which fails one of the tests in the question due to a disagreement over whether hexadecimal strings count are numeric. They even wrote a test validating that it produces behavior contrary to the question. Naturally, it's accepted despite this.
In fact, the question body has, since revision 1, specified "decimal numbers", which, fun fact, clearly does not include hexadecimal numbers. (a later revision added "decimal" to the title as well, just to make the accepted answer more wrong, I guess)
Everything is terrible.
Since it's CW, I added a note to it noting that it doesn't actually answer the question asked.
This is a great example of something we could fix if we could move answers between questions.
 
5 hours later…
3:36 PM
@RyanM Well, yes - has to be inverted. But the answer is just mentioning which function to use and that it returns true if it's not a number. It does, in fact, give you the exact same result as the question asks. Which...is also a problem.
isNaN is very badly named, because the real thing it checks is not "is this value not a number" or "is this value the numeric value NaN". The real check is "if I convert this value to a number, is the result NaN or not". So, isNaN("42") -> false because converting the string "42" to a number produces a valid number. But isNaN("apple") -> true
It's better JS style to use typeof(something) == 'number'. With == rather than ===. Reserve === for when you really mean it. — Adam Chalcraft Feb 22, 2020 at 23:35
*facepalm* yes, we don't want to run out of strategic reserves of equals signs...
To be clear, it's bogus. There is no reason to demand more differences in equality checks. === is literally always correct. There is a single case where a loose (==) equals might be preferable but it's more down to style. There is zero downside to always use ===. There are many potential pitfalls if you use == and === inconsistently.
yeah but if you always use === you'll never be able to do clever coercion stuff to show off your leet skills
That's the point
The single case where == is OK (IMO) is val == null since it checks for both null and undefined. It's useful, since these tend to be interchangeable in many cases for callers. But you probably want to handle both the same.

« first day (3220 days earlier)      last day (38 days later) »