Latest web development tutorials
 

JavaScript Assignment


JavaScript Assignment Operators

Assignment operators assign values to JavaScript variables.

Operator Example Same As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x - y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y

The = assignment operator assigns a value to a variable.

Assignment

var x = 10;
Try it Yourself »

The += assignment operator adds a value to a variable.

Assignment

var x = 10;
x += 5;
Try it Yourself »

The -= assignment operator subtracts a value from a variable.

Assignment

var x = 10;
x -= 5;
Try it Yourself »

The *= assignment operator multiplies a variable.

Assignment

var x = 10;
x *= 5;
Try it Yourself »

The /= assignment divides a variable.

Assignment

var x = 10;
x /= 5;
Try it Yourself »

The %= assignment operator assigns a remainder to a variable.

Assignment

var x = 10;
x %= 5;
Try it Yourself »

Test Yourself with Exercises!

Exercise 1 »  Exercise 2 »  Exercise 3 »  Exercise 4 »  Exercise 5 »