3 ms·
The other gotcha with "typeof": "typeof NaN" is "number", amusingly enough.
by pcwalton 14y ago
The other gotcha with "typeof": "typeof NaN" is "number", amusingly enough.
- krisk 14y agoIndeed. 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 :)
- krisk 14y agoI've written another post which explores NaN in detail: "NaN and typeof" - http://kiro.me/blog/typeof_nan.html http://kiro.me/blog/typeof_nan.html
- crazygringo 14y agoMy 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.