3 ms·
Regular isNaN is very tricky, and almost never what you want: it first coerces its input to a Number, and then checks if that is NaN: isNaN N
by jefftk 5y ago
Regular isNaN is very tricky, and almost never what you want: it first coerces its input to a Number, and then checks if that is NaN:
isNaN Number.isNaN
----- ------------
{} true false
[true] true false
undefined true false
"{}" true false
- jaywalk 5y agoBut none of those things you listed are numbers. The isNaN output is exactly what I want in pretty much every case.
- jefftk 5y agoisNaN does not tell you whether something is not a Number either. Applying isNaN to any of these returns false: null, true, false, [], "", "cabbage".
- dr-detroit 5y ago