In that expression, we have
- initialization =
var i = 0, item
-- this declares two variables, and assigns one of them. - condition =
item = a[i++]
-- this performs an assignment, and tests the result of the assignment - control factor =
nothing
-- the increment ofi
was done as part of the condition, so nothing is needed here
A for-loop
is essentially equivalent to the following:
initialization;
while (condition) {
body;
control factor;
}
So when we substitute from your loop, we get:
var i = 0, item;
while (item = a[i++]) {
// body that you didn't show
}
An assignment's value is the value that was assigned, so the condition is whether a[i]
was truthy. No control factor is needed because a[i++]
returns the value of a[i]
and also increments i
at the same time.
A more typical way to write this loop would be:
for (var i = 0; a[i]; i++) {
var item = a[i];
// body that you didn't show
}
The author was just showing how you can combine many pieces of this.