Why does not IE support the Number.isNaN function? I can't use simple isNan instead of Number.isNaN 'cause these functions are different! For example:
Number.isNaN("abacada") != isNaN("abacada") //false != true
I need to abstract string and number and check, is some var really contains NaN (I mean NaN constant, but not-a-number value like strings).
someobj.someopt = "blah"/0;
someobj.someopt2 = "blah";
someobj.someopt3 = 150;
for(a in someobj) if(Number.isNaN(someobj[a])) alert('!');
That code should show alert for 1 time. But if I will change Number.isNaN to isNaN, it will alert 2 times. There are differences.
May be there is some alternative function exists?
isNaN(x) can also be replaced with a test for x !== x , despite the latter being less readable.
That isNaN(" ") is false is part of the confusing behavior of the isNaN global function due to its coercion of non-numbers to a numeric type. From MDN: Since the very earliest versions of the isNaN function specification, its behavior for non-numeric arguments has been confusing.
To check whether the given number is NaN or finite, we can use JavaScript methods. 1. isNaN() Method: To determine whether a number is NaN, we can use the isNaN() function. It is a boolean function that returns true if a number is NaN otherwise returns false.
isNaN() has become necessary. In comparison to the global isNaN() function, Number. isNaN() doesn't suffer the problem of forcefully converting the parameter to a number. This means it is now safe to pass values that would normally convert to NaN, but aren't actually the same value as NaN.
Why does not IE support the Number.isNaN function?
That's rather off-topic for Stack Overflow, but according to the MDN page for Number.isNaN
, it's not defined in any standard — it's only in the draft spec for ECMAScript 6 — and Internet Explorer is not the only browser that doesn't support it.
May be there is some alternative function exists?
Not really, but you can easily define one:
function myIsNaN(o) {
return typeof(o) === 'number' && isNaN(o);
}
or if you prefer:
function myIsNaN(o) {
return o !== o;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With