tutorialstonight logo

JAVASCRIPT ASSIGNMENT OPERATORS

The assignment operators are used to assign value based on the right operand to its left operand. The left operand must be a variable while the right operand may be a variable, number, boolean, string, expression, object or combination of any other.

One of the most basic assignment operators is equal (=), which is used to directly assign a value.


Assignment Operators List

Here is the list of all assignment operators in JavaScript:

Operator name Operator Meaning
Assignment operator a = 10
Addition assignment operator a += b a = a + b
Subtraction assignment operator a -= b a = a - b
Multiplication assignment operator a *= b a = a * b
Division assignment operator a /= b a = a / b
Remainder assignment operator a %= b a = a % b
Exponentiation assignment operator a **= b a = a ** b
Left shift assignment a <<= b a = a << b
Right shift assignment a >>= b a = a >> b
Unsigned right shift assignment a >>>= b a = a >>> b
Bitwise AND assignment a &= b a = a & b
Bitwise OR assignment a |= b a = a | b
Bitwise XOR assignment a ^= b a = a ^ b
Logical AND assignment a &&= b a = a && b
Logical OR assignment a ||= b a = a || b
Logical nullish assignment a ??= b a = a ?? b

Assignment operator

The assignment operator (=) is the simplest value assigning operator which assigns a given value to a variable.

▶ Try It

The assignment operators support chaining, which means you can assign a single value in multiple variables in a single line.

▶ Try It

Addition assignment operator

The addition assignment operator (+=) is used to add the value of right operand to the value of left operand and assigns the value to the left operand.

On the basic of data type of variable the addition assignment operator may add or concatenate the variables.

▶ Try It

Subtraction assignment operator

The subtraction assignment operator (-=) subtracts the value of right operand from the value of left operand and assigns the value to left operand.

If value can not be subtracted then it results to a NaN.

▶ Try It

Multiplication assignment operator

The multiplication assignment operator (*=) assigns a value to left operand by multiplying value of left and right operand.

▶ Try It

Division assignment operator

The division assignment operator (/=) divides the value of left operand by the value of right operand and assigns the result to the left operand.

▶ Try It

Remainder assignment operator

The remainder assignment operator (%=) assigns the remainder value when the value of left operand is divided by the value of right operand.

▶ Try It

Exponentiation assignment operator

The exponential assignment operator (**=) rises the value of left operator to the power of right operand and assigns the result to the left operand.

▶ Try It

Left shift assignment

The left shift assignment operator (<<=) moves the bit value of left operand by the value of right operand in left direction and assigns the value to left operand.

▶ Try It

Right shift assignment

The right shift assignment operator (>>=) moves the bit value of the left operand in right direction by the value of right operand and assigns the result to left operand.

▶ Try It

Unsigned right shift assignment

The unsigned right shift assignment operator >>>= moves the bit value of left operand in right direction by the value of right operand and results positive output.

▶ Try It

Bitwise AND assignment

The bitwise AND assignment operator (&=) does a bitwise AND operation on the bit value of both the operands and store it to the left operand.

▶ Try It

Bitwise OR assignment

The bitwise OR assignment operator (|=) does a bitwise OR operation on the bit value of both the operands and store it to the left operand.

▶ Try It

Bitwise XOR assignment

The bitwise XOR assignment operator (^=) does a bitwise XOR operation on the bit value of both the operands and store it to the left operand.

▶ Try It

Logical AND assignment

The logical AND assignment operator (&&=) assigns value to left operand only when it is truthy.

Note: A truthy value is a value which is considered true when encountered in boolean context.

▶ Try It

Logical OR assignment

The logical OR assignment operator (||=) assigns value to left operand only when it is falsy.

Note: A falsy value is a value which is considered false when encountered in boolean context.

▶ Try It

Logical nullish assignment

The logical nulish assignment operator (??=) assigns value to left operand only when it is nulish (null or undefined).

▶ Try It