1/0 === Infinity
and 1/Infinity === 0
What is Infinity in JavaScript? ♾️
Infinity is indeed a value in JavaScript, representing mathematical infinity (∞). Be prepared for when it pops ups in your code.
JavaScript: To Infinity
And Beyond
“
Infinity
is a property of the global object, or in other words, a variable in global scope.The initial value of
Infinity
isNumber.POSITIVE_INFINITY
. The valueInfinity
(positive infinity) is greater than any other number. Mathematically, this value behaves the same as infinity; for example, any positive number multiplied byInfinity
equalsInfinity
, and any number divided byInfinity
equals 0.” — MDN Docs
The number Infinity
is a special value in JavaScript that represents mathematical infinity and overflow values — numbers so large they “overflow” the buffer and result in Infinity
.
It results from calculations creating numbers beyond a special maximum value in JavaScript, a value that is about 1.79e+308
or 2¹⁰²⁴— the largest value that can be stored as a number primitive type in JavaScript.
In this article, I explore the behavior of Infinity
in JavaScript.