2

Possible Duplicate:
Why does parseInt(1/0, 19) return 18?

I was parsing an integer from the result of an expression in javascript. The expression was (a/b,24), and it is in a method, so I do not have a check on division by zero. and I am parsing the integer as parseInt(a/b,24)

But I found an unusual thing in it when a=1, b=0 the result was 151176378.

Please explain the reason for this discrepancies.

Appreciate any suggestion.

Community
  • 1
  • 1
Sashi Kant
  • 13,277
  • 9
  • 44
  • 71

1 Answers1

3

When you run parseInt(a/b, 24) you are attempting to parse the result of a/b in base 24 (no idea what this number system would look like).

a/b returns Infinity which is converted to the string value "Infinity" and then parsed using base 24 so you would get the same result with parseInt("Infinity", 24). You would get a result of NaN with any base of 18 or less (i.e. parseInt(1/0, 18)).

Gustav Barkefors
  • 5,016
  • 26
  • 30
detaylor
  • 7,112
  • 1
  • 27
  • 46