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 TypeScript functions as both a unary numeric coercion operator and a binary operator for numeric addition or string concatenation. TypeScript applies strict static type-checking rules to its operands, preventing many of the implicit type coercions permitted in standard JavaScript to enforce type safety.
Unary + Operator
The unary + operator precedes a single operand and evaluates it as a number.
Syntax:
- Valid Operands: TypeScript strictly limits the unary
+operator to operands of typenumber,string,any, and numeric enums. - Return Type: Always resolves to the
numbertype at compile time. - Compiler Restrictions: TypeScript explicitly forbids applying the unary
+to types such asboolean,null,undefined,bigint, orsymbol. Attempting to do so results in a compile-time error.
Binary + Operator
The binary + operator sits between two operands, performing either mathematical addition or string concatenation based on the resolved types of the operands.
Syntax:
+ using the following strict type-checking hierarchy:
- String Concatenation: If either operand is of type
string, the operation is treated as concatenation. The non-string operand is implicitly coerced, and the return type isstring.
- Numeric Addition: If both operands are of type
number(or numeric enums), the operation performs mathematical addition. The return type isnumber.
- BigInt Addition: If both operands are of type
bigint, the operation performs BigInt addition. The return type isbigint.
+ operations between incompatible types.
- Mixed Numerics: You cannot mix
numberandbigint. - Invalid Primitives: You cannot add
boolean,null, orundefinedto anumberor to each other. - Objects/Arrays: You cannot use the
+operator on objects or arrays unless one operand is astringor the types are explicitly cast toany.
Master TypeScript with Deep Grasping Methodology!Learn More





