Possible Duplicate:
Leading zero in javascript
Given you have the following JavaScript snippet:
<script>
var x = 013;
console.log(x);
</script>
Why is it that Firebug prints 11
?
Possible Duplicate:
Leading zero in javascript
Given you have the following JavaScript snippet:
<script>
var x = 013;
console.log(x);
</script>
Why is it that Firebug prints 11
?
JavaScript supports the same convention for numeric constants as C and Java (et al), so the leading zero makes that an octal constant. ("13" in base 8 is 8 + 3, or 11.)
Because you've specified an octal number, but it displays its decimal representation.
It's interpreting it as octal. Any number that begins in zero is interpreted as an octal (base 8) literal, and octal 13 = 8*1+3 = 11 decimal.
Also, good title.
It is being interpreted as base 8. And 013 in base 8 is 11 decimal.
In javascript, constant numbers that begin with 0dd or -0dd and are not 0xdd or -0xdd are interpreted as octal (base 8).
You can see it described in the ECMAScript specification on page 231.
013
is an octal constant - it's interpreted in base 8. 1·8 + 3·1 = 8 + 3 = 11