Alexandar Targov Alexandar Targov - 3 months ago 54
Javascript Question

JavaScript operator ++

i'm having this js code and i can't understand why does the last number is 12 and why it starts counting from 8. Why doen't it strat from 10 and end at 14?

<script type="text/javascript">
var k;
for (k=010; k<015; k++)
document.write(" "+k);


The 0 at the start of your numbers causes the language to interpret them as base 8 ("octal") values. 010 is 8, and 015 is 13.

If you remove the leading 0 characters from your numbers, it will work.

The use of a leading 0 to indicate octal dates back to (at least) C.