JavaScript Increment and Decrement Operators
Syntax
Increment (++) and decrement (--) operators in JavaScript increase or decrease a variable’s value by 1. They can be used in both postfix (e.g., a++) and prefix (e.g., ++a) forms.
++a; // Prefix incrementa++; // Postfix increment
--a; // Prefix decrementa--; // Postfix decrementExample
let count = 0;
console.log(count++); // Outputs: 0 (then count becomes 1)console.log(++count); // Outputs: 2 (count becomes 2, then outputs)
console.log(count--); // Outputs: 2 (then count becomes 1)console.log(--count); // Outputs: 0 (count becomes 0, then outputs)