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,324 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
- 191,680
- 20
- 149
- 239
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
- 14,936
- 9
- 68
- 98