Skip to content

JS Assignment Operators

Syntax

Assignment operators in JavaScript assign values to variables and can also perform operations like addition, subtraction, etc., combined with assignment.

+= // Addition assignment
-= // Subtraction assignment
*= // Multiplication assignment
/= // Division assignment
%= // Modulus assignment
**= // Exponentiation assignment

Example

let number = 20;
number += 10; // 20 + 10 = 30
console.log("After +=: " + number);
number *= 2; // 30 * 2 = 60
console.log("After *=: " + number);
number %= 7; // 60 % 7 = 4
console.log("After %=: " + number);