Increment Decrement in javascript
The ++ and -- operators increase or decrease a number by 1. The prefix form (++i) updates the value and returns the new value; the postfix form (i++) returns the old value then updates. Mixing assignment and ++/-- in the same expression can be confusing, so keep them simple.
Example
let i = 0;
console.log(i++); // logs 0, i becomes 1
console.log(++i); // i becomes 2, logs 2
let n = 5;
n--; // n = 4
--n; // n = 3Use ++ and -- mainly as standalone statements (i++, i--); when you care about the returned value, remember that prefix returns the new value and postfix returns the old one.