Number.isNaN

Nathan Wall nathan.wall at live.com
Fri Dec 14 09:12:53 PST 2012


> Wat? This seems to be a good reason to allow `Object(NaN)` and use the 
> NumberWrapper brand as it cannot be tested via the normal way of 
> `myNaN !== myNaN`. 

But `myNaN === myNaN` is true if `myNaN = Object(NaN)`. Testing against the object is different. Nothing breaks.

    var myNaN = Object(NaN);
    [ 1, 3, myNaN ].indexOf(myNaN); // => 2

Works as expected. The only problem which occurs is when you're working with primitive NaN, in which case the only existing good ways to test for it are `x !== x` and `typeof x == 'number' && isNaN(x)`. The purpose of `Number.isNaN` is to provide a way to test this case which is easier to read and understand. Note that if `x = Object(NaN)` both of these tests fail.

Nathan 		 	   		  


More information about the es-discuss mailing list