Add (+) (Operator/additive)

Add two numeric operands together. See concatenation for Strings.


ECMAScript edition - 2
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Netscape Enterprise Server - 2.0
Opera - 3.0
Property/method value type:Number primitive
JavaScript syntax:-anOperand1 + anOperand2
Argument list:anOperand1An expression that evaluates to a number
anOperand2Another expression that evaluates to a numeric value

The addition operator adds two numeric values together or concatenates one string onto another.

When used with numeric operands, the plus sign adds the values together.

The addition is commutative, meaning that the order of the operands does not affect the outcome of the calculation. However, the calculation is not always associative (so (a+b)+c is not always the same as a+(b+c)) and so the precedence established with the grouping operator might affect the outcome.

The associativity is left to right.

Refer to the operator precedence topic for details of execution order.

If either operand is NaN, the result will be NaN.

The sum of infinity and minus infinity will be NaN, they do not cancel one another out.

The sum of two infinity values of the same sign will be the infinity of that sign.

The sum of infinity and a finite value is equal to the infinite operand.

Internally the sum of two negative zero values is -0. However, the sum of two positive zero value or a positive and negative zero value added together will be +0. At the scripting level however, you cannot determine whether a zero is positive or negative, but its sense may affect subsequent computations.

The sum of zero and a non-zero value will be the non-zero value.

The sum of two non-zero finite values of the same magnitude but opposite signs will be zero.

Provided neither an infinity, a zero or NaN is involved, adding two finite values results in the sum of the two values given that the result will be rounded to its nearest representable value. Where the result exceeds the largest presentable value, infinity will be substituted. A negative infinity may result from an underflow.

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 operator prefers to be a String, then a Number conversion happens and the values are added.

See also:Add then assign (+=), Additive expression, Additive operator, Associativity, Negation operator (-), Operator Precedence, String concatenate (+), Subtract (-), Type conversion, Unary expression, Unary operator


ECMA 262 edition 2 - section - 11.6.1

ECMA 262 edition 2 - section - 11.13

ECMA 262 edition 3 - section - 11.6.1

Wrox Instant JavaScript - page - 37