Can someone please explain to me like I'm five how the first for/in loop works?
A for-in loop does allow any left-hand-side expression (that is, something you could possibly assign to) before the in
, not only plain variables. So
for(a[i++] in {x:1, y:2, z:3})
is just the same as
a[i++] = "x";
a[i++] = "y";
a[i++] = "z";
It seems to me
a[i++]
would evaluate to 1 on the first time through the loop, not 0.
i++
is a postfix expression, so no - it will yield the value 0
(that i
had before) and then increment it. See ++someVariable Vs. someVariable++ in Javascript for details.