Because you use the postfix increment operator variable++
, that means you get the value first and then the variable is incremented.
When you use prefix increment operator ++variable
, the variable gets incremented first and then the value is returned.
var a = 42;
console.log(a++); // shows 42, value is 43
console.log(a); // 43
console.log(++a); // 44
console.log(a); // 44