When the operands are a pair of strings, the plus sign will concatenate them together. This yields a single string combining both values joined end to end.
The string concatenation is not commutative. That is, the position of the two operands will affect the outcome if they are exchanged.
The addition/concatenation operator looks at the arguments and if either is a String already or preferentially converts to one, then a concatenation occurs. If neither argument prefers to be a String then a Number conversion happens and the values are added.
The associativity is left to right.
Refer to the operator precedence topic for details of execution order.
Some conversion of type will occur if a mixture of data types is used in certain contexts.
In string concatenations, when either of the operands is a string, the result will be a string concatenation. The same does not apply when relational expressions are involved when the subtraction operator can be used to coerce a string value into a numeric type.
ECMA 262 edition 2 - section 11.6.1
ECMA 262 edition 3 - section 11.6.1
Wrox Instant JavaScript - page 37
Prev | Home | Next |
String | Up | String literal |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |