Skip to content

Instantly share code, notes, and snippets.

@roylory
Last active October 19, 2018 00:21
Show Gist options
  • Save roylory/cd7681c4e46831ea3dd9 to your computer and use it in GitHub Desktop.
Save roylory/cd7681c4e46831ea3dd9 to your computer and use it in GitHub Desktop.
NaN shits (javascript)
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
@kampytaru
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment