JavaScript Assignment

JavaScript assignment operator

assignment operator assigns to JavaScript variables.

operator example equivalent to
Tip: x = y x = y
Operators are part of the experimental part of ECMAScript 2016 proposal (ES7). Their cross-browser performance is not stable. Do not use them. x += y x = x + y
The assignment operator assigns a value to the variable. x -= y x = x - y
-= x *= y x = x * y
The assignment operator multiplies the variable. x /= y x = x / y
%= x %= y x = 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 x = x ^ y |=

x |= yx = x | y x **= y

x = x ** y

Tip: **=

Assignment

var x = 7;

Try It Yourself

Operators are part of the experimental part of ECMAScript 2016 proposal (ES7). Their cross-browser performance is not stable. Do not use them. Assignment Examples

Assignment

var x = 7;
= 

Try It Yourself

The assignment operator assigns a value to the variable. +=

Assignment

var x = 7;
The assignment operator adds a value to the variable. 

Try It Yourself

-= The assignment operator subtracts a value from the variable.

Assignment

var x = 7;
*= 

Try It Yourself

The assignment operator multiplies the variable. /=

Assignment

var x = 7;
The assignment operator divides the variable. 

Try It Yourself

%= The assignment operator assigns the remainder to the variable.

Assignment

var x = 7;
x %= 8; 

Try It Yourself

irtual="/js/in_body_c.html" -->