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.
When you run
parseInt(a/b, 24)you are attempting to parse the result ofa/bin base 24 (no idea what this number system would look like).a/breturnsInfinitywhich is converted to the string value"Infinity"and then parsed using base 24 so you would get the same result withparseInt("Infinity", 24). You would get a result ofNaNwith any base of 18 or less (i.e.parseInt(1/0, 18)).