Because some browsers extend JavaScript's parseInt
to treat the prefix 0
to mean "octal", and 08
is an invalid octal number.
In the various places you use parseInt
, give it its second argument (the radix — e.g., number base — to use), e.g. parseInt(str, 10)
. (This is a good idea generally, for this very reason.)
I'm surprised that you're still finding this behavior in an up-to-date browser, though, as the ECMAScript5 specification released three and a half years ago explicitly forbids extending parseInt
in that way, as noted in Annex E - Additions and Changes in the 5th Edition that Introduce Incompatibilities with the 3rd Edition:
15.1.2.2: The specification of the function
parseInt
no longer allows implementations to treat Strings beginning with a0
character as octal values.
...and I don't think §B.1.1 - Additional Syntax - Numeric Literals applies to parseInt
.