Skip to content

JS Special Numbers

Syntax

JavaScript includes special numeric values such as Infinity, -Infinity, and NaN (Not-a-Number).

let positiveInfinity = Infinity; // Represents a value too large to represent
let negativeInfinity = -Infinity; // Represents a value too small to represent
let notANumber = NaN; // Represents an invalid number result

Example

console.log(1 / 0); // Outputs: Infinity
console.log(-1 / 0); // Outputs: -Infinity
console.log("text" * 3); // Outputs: NaN
console.log(isNaN("text")); // true, checks if the value is NaN