Assignment Operators
EasyIn plain terms
= assigns a value. Compound operators like +=, -=, *=, /= combine assignment with an operation. They modify the variable in place and return the assigned value.
What you need to know
- •=, +=, -=, *=, /=, %=, **=
- •&=, |=, ^=, <<=, >>=, >>>=
- •Returns assigned value
Try it yourself
Copy the code below and run it in your browser console or a code editor:
let x = 10;
x += 5; // x = 15
x -= 3; // x = 12
x *= 2; // x = 24
x /= 4; // x = 6
let str = 'Hello';
str += ' World'; // "Hello World"
// Chaining (rarely used)
let a = b = c = 0;Learn more
Dive deeper with these trusted resources: