Infinity and -Infinity
suggest change1 / 0; // Infinity
// Wait! WHAAAT?
Infinity is a property of the global object (therefore a global variable) that represents mathematical infinity. It is the same value as Number.POSITIVE_INFINITY.
It is greater than every finite number. Infinity > NaN is false, because any comparison with NaN is false. A positive finite number divided by 0 is Infinity, and so is a number that overflows the finite range. 0 / 0 is NaN, not Infinity. A negative finite number divided by 0 is -Infinity.
-Infinity is mathematical negative infinity. It is less than every finite number.
To get -Infinity you negate Infinity, or get a reference to it in Number.NEGATIVE_INFINITY.
- (Infinity); // -Infinity
Now let’s have some fun with examples:
Infinity > 123192310293; // true
-Infinity < -123192310293; // true
1 / 0; // Infinity
Math.pow(123123123, 9123192391023); // Infinity
Number.MAX_VALUE * 2; // Infinity
23 / Infinity; // 0
-Infinity; // -Infinity
-Infinity === Number.NEGATIVE_INFINITY; // true
-0; // -0 , yes there is a negative 0 in the language
0 === -0; // true
1 / -0; // -Infinity
1 / 0 === 1 / -0; // false
Infinity + Infinity; // Infinity
const a = 0, b = -0;
a === b; // true
1 / a === 1 / b; // false
// Try your own!
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents