Assignment Operators
Assignment operators are used to assign values to variables.
| Operator | Meaning | Example | Same As |
| = | Assign | x = 5 | |
| += | Add and assign | x += 3 | x = x + 3 |
| -= | Subtract and assign | x -= 2 | x = x – 2 |
| *= | Multiply and assign | x *= 2 | x = x * 2 |
| /= | Divide and assign | x /= 2 | x = x / 2 |
| %= | Modulus and assign | x %= 2 | x = x % 2 |

= (Assignment)
This operator assigns a value to a variable.
let x = 5;The value on the right side is stored in the variable on the left side.
You can also assign results of expressions:
let x = 10 + 5; // 15Assignment always works right → left.
+= (Add and Assign)
This adds a value to the variable and updates it.
let x = 10;
x += 5; // x = x + 5
console.log(x); // 15It works exactly like writing:
x = x + value;Also follows + behavior (can concatenate strings):
let x = "Hello ";
x += "World";
console.log(x); // "Hello World"-= (Subtract and Assign)
This subtracts a value from the variable and updates it.
let x = 10;
x -= 3; // x = x - 3
console.log(x); // 7It always converts values to numbers.
let x = "10";
x -= 2;
console.log(x); // 8*= (Multiply and Assign)
This multiplies the variable by a value and stores the result.
let x = 10;
x *= 2; // x = x * 2
console.log(x); // 20Works with type conversion:
let x = "5";
x *= 2;
console.log(x); // 10/= (Divide and Assign)
This divides the variable by a value and updates it.
let x = 10;
x /= 2; // x = x / 2
console.log(x); // 5Special cases:
let x = 10;
x /= 0;
console.log(x); // Infinity%= (Modulus and Assign)
This stores the remainder after division.
let x = 10;
x %= 3; // x = x % 3
console.log(x); // 1Useful in cycles or patterns:
let x = 5;
x %= 2;
console.log(x); // 1