Decrement Operators in Javascript

Below is the implementation of Decrement Operator in Javascript:

Javascript
let x = 5;

// Prefix decrement: decrement x by 1 and then print the
// value (4)
console.log(--x);
// Postfix decrement: print the value of x (4) and then
// decrement x by 1
console.log(x--);
// Output: 3
console.log(x);

Output
4
4
3

Increment and Decrement Operators in Programming

Increment and Decrement Operators are Unary Operators commonly used in programming to increase or decrease the value of a variable by one, respectively. They provide a shorthand way to perform these common operations.

Table of Content

  • Increment Operators
  • Increment Operators in C
  • Increment Operators in C++
  • Increment Operators in Java
  • Increment Operators in Python
  • Increment Operators in C#
  • Increment Operators in Javascript
  • Decrement Operators
  • Decrement Operators in C
  • Decrement Operators in C++
  • Decrement Operators in Java
  • Decrement Operators in Python
  • Decrement Operators in C#
  • Decrement Operators in Javascript
  • Difference between Increment and Decrement Operator

Similar Reads

Increment Operators:

Increment operators are used in programming languages to increase the value of a variable by one. There are two types of increment operators: the prefix increment operator (++x) and the postfix increment operator (x++)....

Increment Operators in C:

Below is the implementation of Increment Operator in C:...

Increment Operators in C++:

Below is the implementation of Increment Operator in C++:...

Increment Operators in Java:

Below is the implementation of Increment Operator in Java:...

Increment Operators in Python:

There are no increment(++) or decrement(–) operators in programming. If we need to increment or decrement the value of a variably by 1, then we can use the increment assignment(+=) or decrement assignment(-=) operators. Below is the implementation:...

Increment Operators in C#:

Below is the implementation of Increment Operator in C#:...

Increment Operators in Javascript:

Below is the implementation of Increment Operator in Javascript:...

Decrement Operators:

Decrement operators are used in programming languages to decrease the value of a variable by one. Similar to increment operators, there are two types of decrement operators: the prefix decrement operator (–x) and the postfix decrement operator (x–)....

Decrement Operators in C:

Below is the implementation of Decrement Operator in C:...

Decrement Operators in C++:

Below is the implementation of Decrement Operator in C++:...

Decrement Operators in Java:

Below is the implementation of Decrement Operator in Java:...

Decrement Operators in Python:

Below is the implementation of Decrement Operator in Python:...

Decrement Operators in C#:

Below is the implementation of Decrement Operator in C#:...

Decrement Operators in Javascript:

Below is the implementation of Decrement Operator in Javascript:...

Difference between Increment and Decrement Operator:

Aspect Increment Operator (++) Decrement Operator (–) Operation Increases the value of a variable by 1. Decreases the value of a variable by 1. Syntax variable++ or ++variable variable– or –variable Order of Execution Post-increment (returns current value, then increments) Pre-increment (increments first, then returns updated value) Post-decrement (returns current value, then decrements) Pre-decrement (decrements first, then returns updated value) Usage Often used in loops and calculations to iterate or count. Useful in similar scenarios where decreasing the value is necessary, such as decreasing a counter or looping backwards. Examples int x = 5;x++; // x is now 6 ++x; // x is now 7 int y = 10;int y = 10;–y; // y is now 8...