Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JS Assignment

JavaScript Assignment Operators

Assignment operators in JavaScript assign values to 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 Logical assignment operators were introduced in ES2020.

The = Operator

The Simple Assignment Operator assigns a value to a variable in JavaScript.

Simple Assignment Examples

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

The += Operator

The Addition Assignment Operator increments a variable by a specified value in JavaScript.

Addition Assignment Examples

The -= Operator

Subtraction Assignment Example

The *= Operator

Multiplication Assignment Example

The **= Operator

Exponentiation Assignment Example

The /= Operator

Division Assignment Example

The %= Operator

Remainder Assignment Example

The <<= Operator

Left Shift Assignment Example

The >>= Operator

Right Shift Assignment Example

The >>>= Operator

Unsigned Right Shift Assignment Example

The &= Operator

Bitwise AND Assignment Example

The |= Operator

Bitwise OR Assignment Example

The ^= Operator

Bitwise XOR Assignment Example

The &&= Operator

Logical AND Assignment Example

The ||= Operator

Logical OR Assignment Example

The ??= Operator

Nullish Coalescing Assignment Example