How can I check whether the input value is NaN
or not without using the isNaN
function?
If you can use ECMAScript 6, you have Object.is
:
return Object.is(obj, NaN);
Otherwise, here is one option, from the source code of underscore.js:
// Is the given value `NaN`?
_.isNaN = function(obj) {
// `NaN` is the only value for which `===` is not reflexive.
return obj !== obj;
};
Also their note for that function:
Note: this is not the same as the native isNaN function, which will also return true if the variable is undefined.
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