Math with Infinity
JavaScriptAll snippets in this category →
Posted on Calculations with Infinity
usually still return Infinity
. While Infinity
is a number, trying to subtract it from another Infinity
isn’t a number anymore.
// both `Infinity` and numbers are numbers
typeof Infinity // ⇒ "number"
typeof 1000 // ⇒ "number"
// regular calculations with `Infinity` still return `Infinity`
Infinity + 1000 // ⇒ Infinity
Infinity - 2000 // ⇒ Infinity
Infinity * 3000 // ⇒ Infinity
Infinity / 4000 // ⇒ Infinity
// some of these return `NaN` when we repeat the calculation with `Infinity`
Infinity + Infinity // ⇒ Infinity
Infinity - Infinity // ⇒ NaN
Infinity * Infinity // ⇒ Infinity
Infinity / Infinity // ⇒ NaN
// both `Infinity` and numbers are numbers
typeof Infinity // ⇒ "number"
typeof 1000 // ⇒ "number"
// regular calculations with `Infinity` still return `Infinity`
Infinity + 1000 // ⇒ Infinity
Infinity - 2000 // ⇒ Infinity
Infinity * 3000 // ⇒ Infinity
Infinity / 4000 // ⇒ Infinity
// some of these return `NaN` when we repeat the calculation with `Infinity`
Infinity + Infinity // ⇒ Infinity
Infinity - Infinity // ⇒ NaN
Infinity * Infinity // ⇒ Infinity
Infinity / Infinity // ⇒ NaN
// both `Infinity` and numbers are numbers
typeof Infinity // ⇒ "number"
typeof 1000 // ⇒ "number"
// regular calculations with `Infinity` still return `Infinity`
Infinity + 1000 // ⇒ Infinity
Infinity - 2000 // ⇒ Infinity
Infinity * 3000 // ⇒ Infinity
Infinity / 4000 // ⇒ Infinity
// some of these return `NaN` when we repeat the calculation with `Infinity`
Infinity + Infinity // ⇒ Infinity
Infinity - Infinity // ⇒ NaN
Infinity * Infinity // ⇒ Infinity
Infinity / Infinity // ⇒ NaN
// both `Infinity` and numbers are numbers
typeof Infinity // ⇒ "number"
typeof 1000 // ⇒ "number"
// regular calculations with `Infinity` still return `Infinity`
Infinity + 1000 // ⇒ Infinity
Infinity - 2000 // ⇒ Infinity
Infinity * 3000 // ⇒ Infinity
Infinity / 4000 // ⇒ Infinity
// some of these return `NaN` when we repeat the calculation with `Infinity`
Infinity + Infinity // ⇒ Infinity
Infinity - Infinity // ⇒ NaN
Infinity * Infinity // ⇒ Infinity
Infinity / Infinity // ⇒ NaN