Name
+= — NN 2 IE J1 ECMA 1
Synopsis
The add-by-value operator. This class of operator combines a regular
assignment operator (=
) with one of the many other
operators to carry out the assignment by performing the stated
operation on the left operand with the value of the right operand.
For example, if a variable named a
has a string
stored in it, you can append a string to a
with
the +=
operator:
a += " and some more."
Without the add-by-value operator, the operation had to be structured as follows:
a = a + " and some more"
Table 11.2 shows all the assignment operators that function this way:
Table 11-2. Assignment Operators
Operator |
Example |
Equivalent |
---|---|---|
+= |
a += b |
a = a + b |
-= |
a -= b |
a = a - b |
*= |
a *= b |
a = a * b |
/= |
a /= b |
a = a / b |
%= |
a %= b |
a = a % b |
<<= |
a <<= b |
a = a << b |
>>= |
a >>= b |
a = a >> b |
>>>= |
a >>>= b |
a = a >>> b |
&= |
a &= b |
a = a & b |
|= |
a |= b |
a = a | b |
^= |
a ^= b |
a = a ^ b |
Example
output += "<H1>Section 2</H1>" total *= .95
Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.