First of all guess the result for the following JavaScript code.
parseInt("04")=?;
parseInt("08")=?;
In JavaScript if the string starts with “0”, the string will be parsed as if it is octal number. (i.e. base 8) instead of decimal number(i.e. base 10).
So if you are parsing a string containing integer value and fear about leading zeroes, always specify the base as shown below.
parseInt("04",10); //(here 10 is the base)
parseInt("08",10);
Leave a Reply