I think what you see is just the result of the last statement, which is $i++
or ++$i
. If you directly type this statement in the console, you see a number outputed as well, even if you don't explicitly output it.
For example, if I run the code directly in Firefox's console, I actually see
10
0
1
...
9
The 10
is the result of the last execution of ++$i
and the others are the console.log
statements, which are only executed after the code terminated (as it seems).
If you use
console.log('Iteration: ' + $i);
then you will see the difference more clearly.
That's also the reason why you see two 9
s, since the result of $i++
(where $i = 9
) is 9
.