I've been looking online for this answer, and it's so simple so I'm embaressed for asking, but what exactly does the "+=" do in javascript. I don't know why but I can't seem to find this on google. Please help.
Asked
Active
Viewed 9,841 times
1
-
4https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators – Tieson T. Aug 06 '14 at 05:15
3 Answers
4
It is syntactic sugar that allows you to add something to a variable and store the result in that variable, that is
x += 2;
is equivalent to
x = x + 2;

Elliott Frisch
- 198,278
- 20
- 158
- 249
2
Suppose
var i = 5;
You can add 6 to i
by writing
i = i + 6;
Or the equivalent short-hand way:
i += 6;

Rowan Freeman
- 15,724
- 11
- 69
- 100