I am not a Javascript expert and I need a little help. What does += means in javascript? Random color generator in JavaScript In the link above, the top voted comment shows a way of having a random color, I tried to figure out what the code means but I don't know what the sign "+=" stands for.
Asked
Active
Viewed 832 times
-7
-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators – Ram Nov 23 '15 at 09:13
-
[Shorthand Assignment operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Addition_assignment) Same as `a = a + b;` – Tushar Nov 23 '15 at 09:13
-
3Possible duplicate of [Short hand assignment operator, +=, True Meaning?](http://stackoverflow.com/questions/16362017/short-hand-assignment-operator-true-meaning) – Saif Nov 23 '15 at 09:14
-
1@Saif That's a Java question. – Ram Nov 23 '15 at 09:15
-
1@Saif That's Java, OP is asking about Java**Script** – Tushar Nov 23 '15 at 09:15
-
shorthand concept is same for all language, isn't it? – Saif Nov 23 '15 at 09:16
-
2@Saif: It's not useful to do anything even vaguely promoting the ongoing confusion between Java and JavaScript. – T.J. Crowder Nov 23 '15 at 09:20
1 Answers
2
+=
is the concatenation equals operator. Often used to append and assign strings;
var s = 'Hello';
s += ' World';
console.log(s); // Hello World

Jivings
- 22,834
- 6
- 60
- 101
-
3*"+= is the concatenation equals operator"* It *can* be. It's also the addition-equals operator. Depends on the operands. – T.J. Crowder Nov 23 '15 at 09:19