JavaScript Assignment


JavaScript Assignment Operators

Assignment operators are like tools that give values to JavaScript variables.

Operator Example Same As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x - y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y
**= x **= y x = x ** y

Shift Assignment Operators

Operator Example Same As
<<= x <<= y x = x << y
>>= x >>= y x = x >> y
>>>= x >>>= y x = x >>> y

Bitwise Assignment Operators

Operator Example Same As
&= x &= y x = x & y
^= x ^= y x = x ^ y
|= x |= y x = x | y

Logical Assignment Operators

Operator Example Same As
&&= x &&= y x = x && (x = y)
||= x ||= y x = x || (x = y)
??= x ??= y x = x ?? (x = y)

Note : The ES2020 version of JavaScript introduced the Logical assignment operators.


The = Operator

The Basic Assignment Operator sets a value for a variable.


The += Operator

The Addition Assignment Operator is a way to increase the value of a variable.


The -= Operator

The Subtraction Assignment Operator takes away a number from a variable.


The *= Operator

The Multiplication Assignment Operator makes a variable bigger by multiplying it.


The **= Operator

The Exponentiation Assignment Operator is used to make a variable become a certain number when it's raised to the power of another number.


The /= Operator

The Division Assignment Operator is used to divide a variable.


The %= Operator

The Remainder Assignment Operator puts the leftover amount into a variable.


The <<= Operator

The Left Shift Assignment Operator makes a variable move to the left.


The >>= Operator

The Right Shift Assignment Operator does this: it moves a variable to the right (if it's a positive number).


The >>>= Operator

The Unsigned Right Shift Assignment Operator makes a variable shift to the right (in a way that doesn't consider negative numbers).


The &= Operator

The Bitwise AND Assignment Operator is a tool that performs AND operation on two operands and then puts the answer into a variable.


The |= Operator

The Bitwise OR Assignment Operator is a tool that performs OR operation on two numbers and then saves the answer in a variable.


The ^= Operator

The "Bitwise XOR Assignment Operator" does XOR operation on two numbers and then puts the answer into a variable.


The &&= Operator

The Logical AND assignment operator works with two values. If the first value is true, it assigns the second value.

Note : The &&= operator is an ES2020 feature.


The ||= Operator

The Logical OR assignment operator connects two values together.

If the initial value is not true, then the second value takes its place.

Note : The ||= operator is an ES2020 feature.


The ??= Operator

The Nullish coalescing assignment operator is placed between two values.

If the initial value isn't there or is empty, the second value takes its place.

Note : The ??= operator is an ES2020 feature.