ECMAScript Assignment Operators

Assignment Operators

Simple assignment operators are implemented by an equal sign (=), which assigns the value on the right side of the equal sign to the variable on the left side.

For example:

var iNum = 10;

Compound assignment operations are implemented by multiplication operators, addition operators, or shift operators plus an equal sign (=). These assignment operators are abbreviations for the following common situations:

var iNum = 10;
iNum = iNum + 10;

The second line of code can be rewritten using a compound assignment operator:

var iNum = 10;
iNum += 10;

Each of the main arithmetic operations and several other operations have compound assignment operators:

  • Multiplication/Assignment (*=)
  • Division/Assignment (/=)
  • Modulus/Assignment (%=)
  • Addition/Assignment (+=)
  • Subtraction/Assignment (-=)
  • Left Shift/Assignment (<<=)
  • Signed Right Shift/Assignment (>>=)
  • Unsigned Right Shift/Assignment (>>>=)