Compound Operators in JavaScript

If your eyes are scanning these operators and your head is already spinning, pop around to our introduction blog which explains what the different JavaScript operators are and which operators fall under each category. If not, read on to find out what the different compound operators are!

What are the different kinds of JavaScript Operators covered in this article?

Compound Operators

  • += Compound Addition Operator
  • -= Compound Subtraction Operator
  • %= Compound Modulo Operator
  • *= Compound Multiplication Operator
  • /= Compound Division Operator

These operators combine an assignment and an arithmetic operator. The operators display similar patterns, but, of course, they use their own respective logic and rhythmic symbols. Scroll down for some examples.

Examples of Compound Operators:

Examples of Compound Operators:

+= Compound Addition Operator

In the below example, we are taking the original value of num, which is 5 and we are adding 10 to it, which is 15.

Compound Addition Operator

-= Compound Subtraction Operator

We give num2 a value of 10 and then we use the operator with the value of 10, and, since we’re subtracting, we end up with the value of 0.

Compound Subtraction Operator

%= Compound Modulo Operator

We have a variable titled num3 and we give it a value of 50 and then we use the operator with a value of 9 and the remainder is 5 and that’s our output.

*= Compound Multiplication Operator

We give num4 a value of 4, use the operator with a value of 9 and this outputs a value of 45.

Compound Modulo Operator

/= Compound Division Operator

Our operator is num5 with a value of 50, we then use the operator with a value of 25 which outputs 2.

Compound Division Operator

Have a look at our video about JavaScript Operators below!

Want to learn more about JavaScript? Book a Course Below!