The only difference between i++
, ++i
, and i += 1
is the value that's returned from the expression. Consider the following:
// Case 1:
var i = 0, r = i++;
console.log(i, r); // 1, 0
// Case 2:
var i = 0, r = ++i;
console.log(i, r); // 1, 1
// Case 3:
var i = 0, r = (i += 1);
console.log(i, r); // 1, 1
In these cases, i
remains the same after the increment, but r
is different, i += 1
just being a slightly more verbose form of ++i
.
In your code, you're not using the return value at all, so no, there is no difference. Personally, I prefer to use i++
unless there is a specific need to use one of the other forms.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…