Math with Infinity
Calculations with Infinity
are pretty rare, and most of them 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
More fire tips
Error handling with try-catch
Read fire tipRelative timestamps with Intl
With JavaScript’s built-in formatter for relative timestamps, we can build strings like “2 months from now” without having to use third party libraries.
Read fire tip