JavaScript Assignment Operators

Assignment operators assign values to JavaScript variables.

Operator Example Same As Demonstration
= x = y x = y The assignment operator assigns a value to a variable:
   var x = 10;      (The value of x is 10)
+= x += y x = x + y The addition assignment operator adds a value to a variable:
   var x = 10;
   x += 5;
             (The value of x is 15)
-= x -= y x = x - y The subtraction assignment operator subtracts a value from a variable:
   var x = 10;
   x -= 5;
             (The value of x is 5)
*= x *= y x = x * y The multiplication assignment operator multiplies a value with a variable:
   var x = 10;
   x *= 5;
             (The value of x is 50)
/= x /= y x = x / y The division assignment operator divides a variable:
   var x = 10;
   x /= 5;
             (The value of x is 2)
%= x %= y x = x % y The modulus assignment operator assigns a remainder to a variable:
   var x = 10;
   x %= 5;
             (10 ÷ 5 = 2 means nothing is leftover, so the value of x is 0)

Back Table of Contents Next