DEV Community

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

Collapse
 
pentacular profile image
pentacular

Those interfaces could have been designed to signal an error out of band, but weren't.

So they return the error indicator like any other value, and since they return type number, this means that number must include those error indicators.

Of course, those error indicators aren't valid numbers, so you end up things of type number which aren't numbers, and so NaN. :)

Ecmascript defines NaN as: 'Number value that is an IEEE 754-2019 “Not-a-Number” value'.

So you can point the blame for this decision at ecma and IEEE, and wish they had decided differently, but this is the way it turned out.

There are some advantages to this design in that they avoid a need to support early exit from numeric pipelines.

And some disadvantages -- the NaNs will happily keep flowing through, contaminating everything they touch, until you actually check to see if you have some.