Skip to content

Instantly share code, notes, and snippets.

@djD-REK
Created September 19, 2019 21:19
Show Gist options
  • Save djD-REK/4484e3cad8c59e47fb989eb86d896c43 to your computer and use it in GitHub Desktop.
Save djD-REK/4484e3cad8c59e47fb989eb86d896c43 to your computer and use it in GitHub Desktop.
const mightBeNaN = NaN // NaN means "Not-a-Number"
// Anything compares false when compared to NaN:
console.log(37 === NaN) // false
console.log(mightBeNaN === NaN) // false
// NaN is the only value that does not equal itself:
console.log(mightBeNaN !== mightBeNaN) // true
// Creating an invalid Date results in the value NaN:
console.log(new Date(`invalid`) !== new Date(`invalid`)) // true
// For improved code readability, some developers prefer Number.isNan():
console.log(Number.isNan(mightBeNaN)) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment