Compound assignment operators

Often in programming, it is necessary to perform an operation on a variable and store the value in the original variable. For example, you might want to multiply a variable by five. Using the assignment operator, you would type:

myVariable = myVariable * 5;

However, JavaScript has a shorthand notation that combines the mathematical operators and the assignment statement. The syntax is

Syntax:

  variable (op)= operand; 

or

myVariable *= 5;

This example is the same as 'myVariable = myVariable * 5'. This notation can be used for any of the operators.