Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

JavaScript Assignment Operators

Uploaded by

pasiteg800
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

JavaScript Assignment Operators

Uploaded by

pasiteg800
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

JavaScript Assignment Operators

Assignment operators assign 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 %= yx = 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 are ES2020.

The = Operator

The Simple Assignment Operator assigns a value to a variable.

Simple Assignment Examples

let x = 10;

let x = 10 + y;

The += Operator

The Addition Assignment Operator adds a value to a variable.

Addition Assignment Examples

let x = 10;

x += 5;

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

The -= Operator

The Subtraction Assignment Operator subtracts a value from a variable.

Subtraction Assignment Example


let x = 10;

x -= 5;

The *= Operator

The Multiplication Assignment Operator multiplies a variable.

Multiplication Assignment Example

let x = 10;

x *= 5;

You might also like