Increment Operator
Postfix (x++)
Using it after the operand (x++)
let x = 3; const y = x++; console.log(x, y); // x:4, y:3
- Original variableis- incremented
- New variableis assigned the original value- before incrementing
Prefix (++x)
Using it before the operand (++x)
let a = 3; const b = ++a; console.log(a, b); // 4, 4
- Original variableand- new variableare both- incremented.