The JavaScript assignment operators are used to assign the right-side operand values to variables. The = sign is used for assigning a value to a variable.
For example, we can perform the increment using the JavaScript assignment operator in the following way:
JavaScript Assignment – Operators
Following are some assignment operators used in JavaScript:
Operator | Example | Same As | Description |
= | x = y | x = y | It is used to assign a value of a variable y to another variable x |
+= | x += y | x = x + y | It is used to assign the result of x plus y to variable x |
-= | x -= y | x = x – y | It is used to assign the result of x minus y to variable x |
*= | x *= y | x = x * y | It is used to assign the result of x multiplied by y to variable x |
/= | x /= y | x = x / y | It is used to assign the result of x divided by y to variable x |
%= | x %= y | x = x % y | It is used to assign the result of x modulus y to variable x |
<<= | x <<= y | x = x << y | It is used to assign the result of x shifted left by y to variable x |
>>= | x >>= y | x = x >> y | It is used to assign the result of x sign preserved shifted right by y to variable x |
>>>= | x >>>= y | x = x >>> y | It is used to assign the result of x shifted right by y to variable x |
&= | x &= y | x = x & y | It is used to assign the result of x AND y to variable x |
^= | x ^= y | x = x ^ y | It is used to assign the result of x XOR y to variable x |
|= | x |= y | x = x | y | It is used to assign the result of x OR y to variable x |
**= | x **= y | x = x ** y | It is used to assign the result of x exponential y to variable x |