Assignment Operators


JavaScript assignment operators are used to assign value to variables.

1. = (Assign)

int a = 10;
document.write(a)

// prints 10

2. += (Add and assign)

int a = 10;
a += 5;
document.write(a)

// prints 15

3. -= (Subtract and assign)

int a = 10;
a -= 5;
document.write(a)

// prints 5

4. *= (Multiply and assign)

int a = 10;
a *= 5;
document.write(a)

// prints 50

5. /= (Divide and assign)

int a = 10;
a /= 5;
document.write(a)

// prints 2

6. %= (Modulus and assign)

int a = 10;
a %= 5;
document.write(a)

// prints 0