What is Infinity in JavaScript?

Infinity is a global property of the global object. It is a number that exceeds any other number. It is read-only, meaning you cannot modify it. We will try to modify it in one of the examples below. Infinity can be negative or positive, as we know in mathematics.

Example: Log Infinity to the console

In the example below, we will log out Infinity to the console.

console.log(Infinity)
console.log(Math.pow(10, 1000)) // Positive infinity

Positive and negative Infinity

Infinity can be negative or positive. It is positive when the value exceeds 1.797693134862315E+308, the upper limit of floating point numbers. And it is negative when it is -1.797693134862315E+308, when a value exceeds the lower limit of floating point numbers.

// create negative and positive infinity values
let negInfinity = -1.797693134862315E+308
let posInfinity = +1.797693134862315E+308
// log to the console
console.log(negInfinity)
console.log(posInfinity)

What is Number.POSITIVE_INFINITY?

Number.POSITIVE_INFINITY is the initial value or start of Infinity. Let’s log it to the console and see its value.

console.log(Number.POSITIVE_INFINITY)

Free Resources