Utilizor
Contact Us

NaN and Infinity

Special number values.

NaN and Infinity

NaN - Not a Number

NaN is a JavaScript reserved word indicating that a number is not a legal number.

Trying to do arithmetic with a non-numeric string will result in NaN.

Infinity

Infinity (or -Infinity) is the value JavaScript will return if you calculate a number outside the largest possible number.

Division by 0 (zero) also generates Infinity.

Example

let x = 100 / "Apple";  // x will be NaN
let y = 2 / 0;          // y will be Infinity