Code highlights logo

Learn

Variables

The Increment and Decrement Operator

The increment and decrement operators are very useful when you need to increase or decrease the value of a variable by one.

The increment operator, represented by ++, is used to add 1 to the value of a variable. For example:

1let count = 0;
2count++;
3console.log(count); // Output: 1

In this example, the value of count is initially 0. After executing count++, the value is increased by 1, resulting in 1.

On the other hand, the decrement operator, represented by --, is used to subtract 1 from the value of a variable. For example:

1let quantity = 5;
2quantity--;
3console.log(quantity); // Output: 4

In this case, the initial value of quantity is 5. After executing quantity--, the value is decreased by 1, resulting in 4.


Instructions

1.

Increment the value of x by 1 using the increment operator (++).

2.

Print the updated value of x to the console.

Sign up to start coding

Already have an account?

Sign In

Course content