Hacker News new | ask | show | jobs
by zastavka 4049 days ago
`isNaN` as it currently exists isn't terribly useful, because anything that can be type-coerced to NaN will return true. If you want to check if something actually is NaN in JS, the common idiom is to test x !== x, since NaN is the only value in JS that is defined as not being equal to itself (don't blame Eich, blame the IEEE floating-point standard). NaN, despite the name, is a "number" that's a result of floating-point calculations with undefined behavior. Sometimes that's a useful thing to test for.

Adding a new, proper isNaN function under a new namespace (Number) lets them do that without breaking the old functionality.