Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

infinity
javascript
communitycreator

What is Infinity in JavaScript?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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)

RELATED TAGS

infinity
javascript
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring