HomeToolsAbout a20k

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 variable is incremented
  • New variable is 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 variable and new variable are both incremented.
© VincentVanKoh