🔢NaN
not a number.
JS ⟩ scope ⟩ global ⟩ global object ⟩ property ⟩ NaN
( non-configurable, non-writable global object property )❗
a property of the global object. (that is, a variable in global scope).
equivalent to Number.NaN.
NaN is the only value that doesn't equal to itself❗
// ⭐️ `NaN` is the ONLY ONE that doesn't equal to itself.
NaN === NaN, // false❗️
NaN !== NaN, // true❗️
// equivalent forms
Number.isNaN(x) === (x !== x)trichotomy law: a < b, a = b, a > b doesn't apply to NaN❗
3 < NaN, // false❗
3 == NaN, // false❗
3 > NaN, // false❗isNaN(x)will try to convertxto a number first❗Number.isNaN(x)never do conversions.
for Number.isNaN(x) to be true, x must be a number first❗️
0/0 evaluates to NaN (no error)❗
non-numeric operand(s) in arithmetic operations that cannot convert to numbers convert to NaN.
if either operand is (or converts to) NaN, the result is false.
👉 Infinity
replit: NaN
// ⭐️ `NaN` is the ONLY ONE that doesn't equal to itself❗️
// -------------------------------------------------------
//
// `x !=== x` is equivalent to `Number.isNaN(x)`
//
NaN === NaN, // false❗️
NaN !== NaN, // true❗️
Number.isNaN(NaN), // true (⭐️ the ONLY value that makes this true❗️)
// ⭐️ isNaN() tries to convert to a number first❗️
Number('foo'), // NaN
isNaN('foo'), // true❗️ ('foo' -> NaN)
Number('123abc'), // NaN
isNaN('123abc'), // true❗️ ('123abc' -> NaN)
// ⭐️ Number.isNaN() NEVER converts anything❗️
// --------------------------------------------
// for `Number.isNaN(x)` to be true, `x` must be a number first❗️
Number.isNaN('foo'), // false❗️ (⭐️ `false` for non-numeric values❗️)
Number.isNaN(2 / 'foo'), // trueLast updated
Was this helpful?