Search code examples
javascriptdivide-by-zero

Why 0/0 is NaN and not infinity in Javascript


Division by zero (1/0, 2/0, 3/0, etc) produces infinity. However 0/0 produces NaN. Why?


Solution

  • Mathematically it's most certainly not infinity. if it was obtained from limit x^2/x as x -> 0, it should be 0, for instance. x/x^2 would give infinity, though.

    It's an indeterminate form, and in some sense more indeterminant than 1/0, 2/0 etc. In short, much more of your math would be mucked up from replacing 0/0 with Infinity than replacing 1/0 with infinity, because it's not clear that the denominator effect of dividing by zero should overwhelm the multiplication by zero effect of the numerator.