3

0 / 0 outputs NaN while 1 / 0 outputs Infinity

How javascript evaluates the first mathematical operation?

3 Answers3

2

As per spec

0 / 0 outputs NaN because

Division of a zero by a zero results in NaN; division of zero by any other finite value results in zero, with the sign determined by the rule already stated above.

and 1 / 0 outputs Infinity because

Division of a nonzero finite value by a zero results in a signed infinity. The sign is determined by the rule already stated above.

Point 7 and 8 in the section 12.6.3.2 Applying the / Operator (unordered list)

gurvinder372
  • 66,980
  • 10
  • 72
  • 94
0

In javascript, 0 / 0 and 1 / 0 denote the division of IEEE754 floating point type arguments.

This floating point specification is very specific about what must happen when a division where the denominator is zero is evaluated. It returns

  1. +Infinity if the numerator is positive
  2. -Infinity if the numerator is negative
  3. NaN if the numerator is also zero

Hence 0 / 0 is NaN, and 1 / 0 is +Infinity.

Note that in other languages (e.g. C, C++, and Java) your division would take place in integer arithmetic, and integer division by zero is not defined.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
0

0/0 is the expression which math can not execute. that is why it is Not_A_Number.