Because of JSLint, I almost always use i += 1
to increment a JavaScript for loop, but for quick and dirty scripts, I use i++
instead.
However, I se
The difference is that i++
returns the value of i
before incrementing and ++i
the value of i
after incrementing. There is no difference if you ignore the return value, e.g. in:
for (var i = 0; i < 10; i++) {
}
The habit of using ++i
over i++
comes from C, where people were worried that storing the old value for i
in i++
would incur a performance penalty.