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
isincremented
New variable
is assigned the original valuebefore incrementing
Prefix (++x
)
Using it before the operand (++x
)
let a = 3; const b = ++a; console.log(a, b); // 4, 4
Original variable
andnew variable
are bothincremented
.