3

I recently saw the Infinity Number used to set a max number of listeners for an event emitter in node.

Infinity has some interesting behavior associated with it. If multiplied/added/subtracted by any other number its result will be Infinity. This seems like it would cause unexpected/unwanted behavior if ever used.

Why is it even in the spec? here In what case would you ever need to use Infinity? What was the purpose of creating it in the language?

In this question here there is a use case that uses it to find a max number from a list of numbers. Although this example works, the Infinity value is not needed to accomplish the task. It could be done very easily without it.

jkdev
  • 11,360
  • 15
  • 54
  • 77
skellertor
  • 916
  • 1
  • 9
  • 26
  • 1
    "*Why is it even in the spec?*" - because JavaScript uses standard IEEE 754 floating point numbers, and those have an infinity value. – Bergi Feb 25 '19 at 21:45

0 Answers0