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.
Infinity
to the consoleIn the example below, we will log out Infinity
to the console.
console.log(Infinity)console.log(Math.pow(10, 1000)) // Positive infinity
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 valueslet negInfinity = -1.797693134862315E+308let posInfinity = +1.797693134862315E+308// log to the consoleconsole.log(negInfinity)console.log(posInfinity)
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)