Increment and Decrement Operators
Increment and Decrement are operations used to increase or decrease a variable's value by 1
.
Increment
The increment operation is performed using the ++
operator:
1234567let a = 0; a++; console.log(a); a++; console.log(a); a++; console.log(a);
Note
The expression
a++
is equivalent toa = a + 1
ora += 1
.
Decrement
The decrement operation is performed using the --
operator:
1234567let a = 5; a--; console.log(a); a--; console.log(a); a--; console.log(a);
Note
The expression
a--
is equivalent toa = a - 1
ora -= 1
.
Increment and decrement operations are frequently used in loops, which we will discuss in more detail later.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 2.33
Increment and Decrement Operators
Swipe to show menu
Increment and Decrement are operations used to increase or decrease a variable's value by 1
.
Increment
The increment operation is performed using the ++
operator:
1234567let a = 0; a++; console.log(a); a++; console.log(a); a++; console.log(a);
Note
The expression
a++
is equivalent toa = a + 1
ora += 1
.
Decrement
The decrement operation is performed using the --
operator:
1234567let a = 5; a--; console.log(a); a--; console.log(a); a--; console.log(a);
Note
The expression
a--
is equivalent toa = a - 1
ora -= 1
.
Increment and decrement operations are frequently used in loops, which we will discuss in more detail later.
Thanks for your feedback!