Last active
April 7, 2017 18:16
-
-
Save mikepenzin/7a0e32a17b4a34a763a4bb663e4b0903 to your computer and use it in GitHub Desktop.
Reliably test if a value is equal to NaN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkNaN(n){ | |
return (n !== n) ? true : false; | |
} | |
/* | |
If we will use regular "isNaN": | |
isNaN(NaN); // true | |
isNaN(undefined); // true | |
isNaN({}); // true | |
isNaN('123ABC'); // true | |
isNaN(new Date().toString()); // true | |
isNaN('blabla'); // true: "blabla" is converted to a number. | |
If we will use checkNaN function: | |
checkNaN(NaN); // true | |
checkNaN(undefined); // false | |
checkNaN({}); // false | |
isNaN('123ABC'); // false | |
isNaN(new Date().toString()); // false | |
isNaN('blabla'); // false | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment