JavaScript Assignment Operators

๐Ÿ“˜ What are Assignment Operators?

Assignment operators are used to assign values to variables. They can also perform an operation and assignment in one step.

= Basic Assignment Operator

let x = 10;
console.log(x); // 10
            

๐Ÿงฎ Common Assignment Operators

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

๐Ÿ’ป Examples

let a = 10;

a += 5;  // a = a + 5 โ†’ 15
a -= 3;  // a = a - 3 โ†’ 12
a *= 2;  // a = a * 2 โ†’ 24
a /= 4;  // a = a / 4 โ†’ 6
a %= 4;  // a = a % 4 โ†’ 2
            
โœ… Assignment operators make your code shorter and cleaner.

๐Ÿงช Try It Yourself

Click the button to apply assignment operators step by step: