Last active
October 19, 2018 00:21
-
-
Save roylory/cd7681c4e46831ea3dd9 to your computer and use it in GitHub Desktop.
NaN shits (javascript)
This file contains hidden or 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
NaN==NaN // false, wtf? | |
isNaN(NaN) // true | |
isNaN(0/0) // true | |
isNaN(10) // false | |
isNaN("10") // false | |
isNaN("any string that can't become number") // true | |
isNaN(true) // false | |
isNaN(false) // false | |
typeof NaN === 'number' // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
isNaN(function() { return 55 }) // true
isNaN([1, 2, 3]) // true
So their logic works "most of the time" but not all of the time such as when you do 0/0. if you typeof (0/0) === "number" that will return true since 0/0 = 0 and 0 is a number.