Mathematical Assignment Operators

Normal mathematical assignment operators:

let w = 4;
w = w + 1;

console.log(w);		// Output: 5

let a = 10;
a = a - 5;

console.log(a);		// Output: 5

let b = 100;
b = b * 20;

console.log(b);		// Output: 2000

let c = 20;
c = c / 20;

console.log(c);		// Output: 1

Mathematical assignment operators using javascripts builtin operators:

let w = 4;
w += 1;

console.log(w);		// Output: 5

let a = 10;
a -= 5;

console.log(a);		// Output: 5

let b = 100;
b *= 20;

console.log(b);		// Output: 2000

let c = 20;
c /= 20;

console.log(c);		// Output: 1

Last updated