++i vs. i++
Last updated
Last updated
++i
vs. i++
in JavaScriptSame as in other languages:
++i
(pre-increment) means "increment the variable; the value of the expression is the final value"
i++
(post-increment) means "remember the original value, then increment the variable; the value of the expression is the original value"
I was confused as to what arr[index++]
does in the question
Answer:
arr[index++]
is the same as:
So in the loop above the would reference arr[1]
and then assign the right hand value. AND THEN increment.
|