JavaScript Assignment Operators

JavaScript Assignment Operators

Author
Nguyen Bao Huy
04:59:00 09/02/2026
2 min read
0 comments

JavaScript Assignment Operators

Assignment operators assign values to JavaScript variables.

OperatorExampleSame As
=x = yx = y
+=x += yx = x + y
-=x -= yx = x - y
*=x *= yx = x * y
/=x /= yx = x / y
%=x %= yx = x % y
**=x **= yx = x ** y

Shift Assignment Operators

OperatorExampleSame As
<<=<<= x <<= yx = x << y
>>=x >>= yx = x >> y
>>>=x >>>= yx = x >>> y

Bitwise Assignment Operators

OperatorExampleSame As
&=x &= yx = x & y
^=x ^= yx = x ^ y
|=x |= yx = x | y

Logical Assignment Operators

OperatorExampleSame As
&&=x &&= yx = x && (x = y)
||=x ||= yx = x || (x = y)
??=x ??= yx = x ?? (x = y)
Note: The logical assignment operators are ES2020

The = Operator

The Simple Assignment Operator assigns a value to a variable.

javascript
let x = 10;
let x = 10 + y;

The += Operator

The Addition Assignment Operator adds a value to a variable.

javascript
let x = 10;x += 5;

let text = "Hello"; text += " World";

The -= Operator

The Subtraction Assignment Operator subtracts a value from a variable.

javascript
let x = 10;
x -= 5;

The *= Operator

The Multiplication Assignment Operator multiplies a variable.

javascript
let x = 10;
x *= 5;

The **= Operator

The Exponentiation Assignment Operator raises a variable to the power of the operand.

javascript
let x = 10;
x **= 5;

The /= Operator

The Division Assignment Operator divides a variable.

javascript
let x = 10;
x /= 5;

The %= Operator

The Remainder Assignment Operator assigns a remainder to a variable.

javascript
let x = 10;
x %= 5;

The <<= Operator

The Left Shift Assignment Operator left shifts a variable.

javascript
let x = -100;
x <<= 5;

The >>= Operator

The Right Shift Assignment Operator right shifts a variable (signed).

javascript
let x = -100;
x >>= 5;

The >>>= Operator

The Unsigned Right Shift Assignment Operator right shifts a variable (unsigned).

javascript
let x = -100;
x >>>= 5;

The &= Operator

The Bitwise AND Assignment Operator does a bitwise AND operation on two operands and assigns the result to the the variable.

javascript
let x = 10;
x &= 5;

The |= Operator

The Bitwise OR Assignment Operator does a bitwise OR operation on two operands and assigns the result to the variable.

javascript
let x = 10;
x |= 5;

The ^= Operator

The Bitwise XOR Assignment Operator does a bitwise XOR operation on two operands and assigns the result to the variable.

javascript
let x = 10;
x ^= 5;

The &&= Operator

The Logical AND assignment operator is used between two values. If the first value is true, the second value is assigned.

javascript
let x = 10;
x &&= 5;

The &&= operator is an ES2020 feature.

The ||= Operator

The Logical OR assignment operator is used between two values. If the first value is false, the second value is assigned.

javascript
let x = 10;
x ||= 5;

The ??= Operator

The Nullish coalescing assignment operator is used between two values. If the first value is undefined or null, the second value is assigned.

javascript
let x;
x ??= 5;

The ??= operator is an ES2020 feature.

Author avatar

Nguyen Bao Huy

Lead Fullstack & AI Solutions Engineer

Specializing in Next.js App Router, React 19, TypeScript, and modern design systems. Passionate about creating seamless user experiences.

Discussion

0

No comments yet

Be the first to share your thoughts, question a concept, or provide additional tips!

Leave a Reply

Share your insights, questions, or solutions with the developer community.

Your avatar
0 / 500 characters