Here’s a lesson I’ve forgotten and re-learned a couple of times, maybe it’ll save someone some time someday.
Javascript’s NaN (not a number) token is a bit tricky sometimes. For example:
a = 0 / 0; // a is now NaN
a == NaN; // return false
typeof a; // returns "number", despite the perhaps
// misleading name "not a number"
There are good reasons for this if you think about it, but I’ll leave that as an excercise for the reader.
2 comments
Because NaNs should not be directly comparable? Isn’t there a ===?
There is a === operator, but NaN === NaN returns false, as far as I know.
Leave a Comment