TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
+ 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:- 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 internalvalueOf()ortoString()methods). - 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., mixingNumberandBigInt), the engine throws aTypeError. - If either operand is a Symbol, the engine throws a
TypeErroras Symbols cannot be implicitly coerced to strings or numbers.
- If either of the resulting primitive values is a String, the engine applies the
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
Master JavaScript with Deep Grasping Methodology!Learn More





