I++; vs i += 1;

Well, something else must be wrong, because while there are differences, they shouldn’t matter to your code.

i++ is a postfix increment, basically it first returns the variable value, then increments the variable.
i += n is an addition assignment, basically adds the values somehow and assigns it to the first variable

In both cases you are just adding 1, but doing nothing else with the return value, so it should work.

Basically what would happen if you tested these things out in the console:

var i = 0
i++ // 0
i  // 1

// using +=
i = 0
i += 1   // 1
i += '2' // '12'

// there's also the prefix increment, it's like the postfix increment,
// but it first assigns the value to the variable, then returns the value
i = 0
++i // 1
i   // 1 
4 Likes