In JavaScript, why does zero divided by zero return NaN, but any other divided by zero return Infinity?

Because that’s how floating-point is defined (more generally than just Javascript). See for example:

  • http://en.wikipedia.org/wiki/Floating-point#Infinities
  • http://en.wikipedia.org/wiki/NaN#Creation

Crudely speaking, you could think of 1/0 as the limit of 1/x as x tends to zero (from the right). And 0/0 has no reasonable interpretation at all, hence NaN.

Leave a Comment

tech