JavaScript array iteration - MDN example -
i reading re-introduction javascript on mdn website , came across example in array section:
for (var = 0, item; item = a[i++];){ // item }
where "a[]" array being looped over.
i confused value "item" have in first iteration. i=0 , item @ first undefined, when assigned value of a[i++] wouldn't iteration start i=1, mean iteration start second element in a[] array -> a[1], skipping on first element a[0] entirely?
i++
post increment operator, means increments i
1
evaluates old (non-incremented) value.
> = 0 0 > i++ 0 > 1
Comments
Post a Comment