2 ms·
One wonders if this blog post would have been written at all if the author was familiar with NaN in floating-point numbers and knew that isNaN was a thing. isN
by beering 14y ago
One wonders if this blog post would have been written at all if the author was familiar with NaN in floating-point numbers and knew that isNaN was a thing.
isNaN is the defined method of checking if something Not A Number or can't be converted into a number.
The Real WTF (and infamous "feature" of JS) is that many things can be converted into a number.
isNaN("string") => true
isNaN({}) => true
but you might not expect that
isNaN("3e2") => false
isNaN("") => false
isNaN([]) => false
- mbrubeck 14y agoThe "Harmony" proposal for the next JavaScript spec includes Number.isNaN, which is meant to be a less-confusing version (with no type coercion). It's currently implemented in Firefox Nightly builds: http://bugzil.la/749818 http://bugzil.la/749818 Number.isNaN(NaN) => true Number.isNaN(3e2) => false Number.isNaN("NaN") => false Number.isNaN("string") => false Number.isNaN({}) => false Number.isNaN("3e2") => false Number.isNaN([]) => false http://wiki.ecmascript.org/doku.php?id=harmony:number.isnan http://wiki.ecmascript.org/doku.php?id=harmony:number.isnan