Technology, politics and the rest
Header picture

Javascript Reminder

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

1 Girts { 04.30.08 at 9:50 pm }

Because NaNs should not be directly comparable? Isn’t there a ===?

2 Matt { 04.30.08 at 10:17 pm }

There is a === operator, but NaN === NaN returns false, as far as I know.

Leave a Comment

You might also want to register or log in