The Power of Javascript: Operators continued - Assignment Operators
(Page 4 of 5 )
We have been using the assignment operator (=) since the first article in the series. Assignment operators are binary operators that assign the value of their right operands to the variable on their left operands. The assignment operator (=) can be combined with the arithmetic operators or with the bitwise operators to offer you a way to perform an operation, then an assignment, as a shortcut statement. Let's take a look at those assignment operators.
Operator | Operator Explanation |
| += | The statement x += 1 is the same as x = x + 1; It's like saying assign the value 1 to the value of x. |
| -= | x -= 1 is the same as x = x - 1; |
| *= | x *= 2 is the same as x = x * 2; |
| /= | x /= 2 is the same as x = x / 2; |
| %= | x %= 2 is the same as x = x % 2; |
| &= | x &= 2 is the same as x = x & 2; |
| |= | x |= 2 is the same as x = x | 2; |
| ^= | x ^= 2 is the same as x = x ^ 2; |
| >>= | x >>= 2 is the same as x = x >> 2; |
| <<= | x <<= 2 is the same as x = x << 2; |
Next: Assignment Operators Example >>
More JavaScript Articles
More By Michael Youssef