Notes
The =
assignment operator assigns a value to a variable.
var x = 2;
document.write(x);
Output: 2
The +=
assignment operator adds a value to a variable.
var x = 2;
x += 2
document.write(x);
Output: 4
The -=
assignment operator subtracts a value from a variable.
var x = 5;
x -= 2
document.write(x);
Output: 3
The *=
assignment operator multiplies a variable.
var x = 4;
x *= 3;
document.write(x);
Output: 12
The /=
assignment divides a variable.
var x = 15;
x /= 3;
document.write(x);
Output: 5
The %=
assignment operator assigns a remainder to a variable.
var x = 11;
x %= 4;
document.write(x);
Output: 3