Javascript - Operator Assignment Operators

Introduction

Assignment is = and assigns the value on the right to the variable on the left:

var num = 10;

Compound assignment is one of the multiplicative, additive, or bitwise-shift operators followed by an equal sign =.

These assignments are designed as shorthand for such common situations as this:

var num = 10;
num = num + 10;

The second line of code can be replaced with a compound assignment:

var num = 10;
num += 10;

Compound-assignment operators are as follows:

Meaning Operator
Multiply/assign *=
Divide/assign /=
Modulus/assign %=
Add/assign+=
Subtract/assign -=
Left shift/assign <<=
Signed right shift/assign>>=
Unsigned right shift/assign >>>=

Exercise