In programming, it is common to use assignments to modify the contents of a variable. Remember that everything to the right of the equals sign is evaluated first, so we can say:
myVar =
myVar + 7;
to add 7 to myVar. Since this is such a common pattern, there are operators which do both a mathematical operation and assignment in one step.
One such operator is the += operator.
var myVar =
1;
myVar +=
5;
console.log(myVar);
// Returns 6
Exercices
Convert the assignments for a, b, and c to use the += operator.
= a + 12
;
= 9 + b
;
= c + 7
;