DEV Community

Discussion on: I've always been using isNaN wrong! (and you?)

Collapse
 
aminmansuri profile image
hidden_dude

In IEEE 754 floating point numbers NaN is a special value for the number that represents the result of an operation that yields a number that isn't a real number. For example: dividing by zero, or taking the square root of -1 (i is not a real number).

en.wikipedia.org/wiki/NaN

So, yeah, in most computer languages NaN IS a specific value of the number type system. Ie. it has a specific binary representation.

So when I first saw your code asking isNan(string) I was a bit surprised that could even work.. But then again, in JavaScript weird things happen.

So while your code seems to work fine (without the linter change), it violates the principle of least surprise. Because many programmers would expect that isNaN() would work like Number.isNaN(). Which is technically more "correct".