In my last question, I discovered that a number with a leading 0 is parsed as an octal number. In this question, the answer says:
This is a common Javascript gotcha with a simple solution:
Just specify the base, or 'radix', like so:
parseInt('08',10); // 8
That works, but only if the number is enclosed in quotes. Consider the following example:
var test = 0132;
alert(parseInt(test, 10));
JSFiddle: http://jsfiddle.net/VU96M/2/
The output of that is "90," not "132."
So, as you can see, the solution does not work int this case.
If I have a variables passed to a function as a parameter, or returned from a function, that has a leading zero like the above variable test
, how can I parse it as a base 10 value?