Javascript - NaN (Not a number)

1 - About

3 - Nan is not equal to itself

The IEEE floating-point standard requires that NaN must be treated as unequal to itself.

console.log(NaN === NaN);    // false

4 - isNaN


console.log(isNaN(NaN));    // true

  • but the below expressions are also TRUE !!

console.log(isNaN("foo"));              // true
console.log(isNaN(undefined));          // true
console.log(isNaN({}));                 // true

  • you check then a NaN value not with the isNaN function but with the fact that this is the only value not equal to itself

var foo = NaN;
console.log(foo !== foo);    // true; This is NaN
var bar = "bar";
console.log(bar !== bar);    // false; This is not a NaN

4.1 - Utility function isReallyNaN


function isReallyNaN(x) {
    return x !== x;
}

console.log(isReallyNaN(NaN));
console.log(isReallyNaN("bar"));

5 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap