DEV Community

Discussion on: 20 Killer JavaScript One-Liners That’ll Save You Hours of Coding 🤯🔥

Collapse
 
codingjlu profile image
codingjlu

IMO infinity is not a number.

Collapse
 
scriptneutron profile image
script-neutron

Yes

Collapse
 
josefheld profile image
Josef Held

Well, in JS it is a number.
maybe calling it Infinity was a poor choice 😉

Collapse
 
pcjmfranken profile image
Peter Franken

Agreed, which makes it all the more useful to know that it's classified as one in JS anyway (and in fact by most other software and runtimes too, due to the IEEE 754 standard for floating-point arithmetic).

The isFinite global function (spec, MDN) might come in handy next time you need to validate a numerical type.

Collapse
 
kitanga_nday profile image
Kitanga Nday

Infinity is a number in math. I think it's set this way for internal reasons, but outside of programming infinity is a number

Thread Thread
 
pcjmfranken profile image
Peter Franken

At the risk of sounding super pedantic, it would be more accurate to say infinity represents a number (a quantity) rather than actually being one itself. Unlike maths' infinity which can actually represent different measures, JS' version is essentially just an "out of bounds" indicator (x+n) within our "fake" digital/binary arithmetic and therefore only infinite on a philosophical level.

Funny when you realise that JS' infinity is actually, at its most basic level, a very much finite amount of ones and zeroes.