The main assignment operator is a regular equal sign ("="), for instance:
var num = 8;
In combinations with a multiplicative, additive or bitwise-shift operators, the assignment operator becomes a compound assignment operator. These operators are used as shorthand for many situations, such as these:
var num = 8;
num = num + 4;
This example can be re-written as shown here:
var num = 8;
num += 4;
This is the complete list of the compound assignment operators:
- *= (multiply / assign);
- /= (divide / assign);
- %= (modulus / assign);
- += (add / assign);
- -= (subtract / assign);
- < <= (left sign / assign);
- >>= (signed right shift / assign);
- >>>= (unsigned right shift / assign);
Example
The example with assignment operators in JavaScript:
Comments
Please login to leave a comment. Login now