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

There is more to learn

Get free previews of my upcoming course materials and other bonus content to help you work smarter. I share tips straight to your inbox once a week. You can read previous mails in the newsletter archive.

Cannot show form because cookie consent was not given.