Hacker News new | ask | show | jobs
by pcwalton 5117 days ago
The other gotcha with "typeof": "typeof NaN" is "number", amusingly enough.
2 comments

Indeed. That's because ECMAScript standard states that Numbers should be IEEE-754 floating point data, which includes positive and negative infinity, and also NaN. Hence why, in JS, it's part of the Number object: Number.NaN. Technically, it's stil a numeric data type, but just points to an invalid number :)
I've written another post which explores NaN in detail: "NaN and typeof" - http://kiro.me/blog/typeof_nan.html
My biggest WTF was when I discovered that parseFloat("Infinity") returns... Infinity itself.

I was working on a site that dealt with English dictionaries, and had a field where you could enter either an English word, OR a number with decimals that represented its frequency. And one day I actually typed in "Infinity" as a test word, and program execution went down a completely unexpected code path... Probably the most surprised I've ever been by a bug.