Skip to main content
The + operator in JavaScript is a polymorphic operator that performs either numeric addition or string concatenation depending on the types of its evaluated operands. It also functions as a unary operator to explicitly coerce a single operand into a numeric value.

Syntax

Binary Operator Mechanics

When used as a binary operator, the JavaScript engine follows a strict evaluation algorithm defined by the ECMAScript specification to determine whether to add or concatenate. The engine resolves the operation through the following sequence:
  1. Primitive Conversion: The engine applies the internal ToPrimitive() abstract operation to both operands. Objects and Arrays are converted to their primitive values (typically by invoking their internal valueOf() or toString() methods).
  2. Type Evaluation:
    • If either of the resulting primitive values is a String, the engine applies the ToString() abstract operation to both operands and performs string concatenation.
    • If neither primitive value is a String, the engine applies the ToNumeric() abstract operation to both operands and performs numeric addition. If the operands resolve to different numeric types (e.g., mixing Number and BigInt), the engine throws a TypeError.
    • If either operand is a Symbol, the engine throws a TypeError as Symbols cannot be implicitly coerced to strings or numbers.

Coercion Behavior

Unary Operator Mechanics

When used as a prefix to a single operand, the unary + operator directly triggers the internal ToNumber() abstract operation. It bypasses string concatenation logic entirely and attempts to parse the operand into an IEEE 754 double-precision float. Because the operation strictly enforces ToNumber(), applying the unary + to a BigInt or Symbol will throw a TypeError.

Unary Coercion Behavior

Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More