Why is the result of parseInt("08") is 0 and not 8?
Good question, I had no idea.
If the input string begins with "0", radix is eight (octal). This feature is non-standard, and some implementations deliberately do not support it (instead using the radix 10). For this reason always specify a radix when using parseInt.
I don't actually use parseInt, I use Number().
What you would actually want to be using is parseFloat as it automatically removes any zero's proceeding the number you want, see the following jsFiddle to see the result.
It was a question that i was asked and it got me confused.
Now jsfiddle is showing 8 for it with default redix. Interesting!!!! I am going to spend some more time on it later in the evening.
If you are trying to convert a string to a number then a better function to use is Number('08) or even +'08'
This topic is now closed. New replies are no longer allowed.