News for hackers. Stuff that matters.
Re:Why does parseInt(1/0, 19) return 18? by chris_wot on Wednesday July 11, 2012 @08:55AM (#4229002)
Division by zero doesn't return a string. It returns a well defined value that is within the domain of the data type, which is positive infinity. parseInt does what it is specified to do - it takes the numerical value (positive infinity) and converts it to a string, then searches the string for the first character that it recognises as a contiguous number ("I", which is 18 in base 19). If it finds one, then it returns the value as an integer, if not then it returns NaN.

So not a bug, though I agree the string search is particularly silly. It can't be a bug if it does what the specified algorithm says it does. It would be a bug if it gave a different result.

There are no comments on this comment yet.