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 is the bitwise XOR (exclusive OR) operator. It evaluates two numeric operands by performing a logical exclusive OR operation on each corresponding pair of bits. For standard number operands, this involves converting them to 32-bit signed integers, whereas bigint operands operate at arbitrary precision.
The operator evaluates bits according to the following truth table:
0 ^ 0yields01 ^ 1yields00 ^ 1yields11 ^ 0yields1
Evaluation Mechanics
When the TypeScript compiler transpiles and the JavaScript engine executes the^ operator, the execution behavior depends strictly on the type of the operands:
For number and numeric enum operands:
- Type Coercion and Truncation: Both operands are converted to 32-bit signed integers using two’s complement representation. Any fractional components are discarded (e.g.,
5.9becomes5). - Bitwise Comparison: The engine aligns the 32 bits of both operands and compares them positionally.
- Return Value: A new 32-bit signed integer is returned based on the XOR evaluation of the bit pairs.
bigint operands:
The operands are not truncated to 32 bits. The engine aligns the binary representation of the arbitrary-precision integers and performs the XOR operation across all bits, returning a new bigint.
TypeScript Type Constraints
TypeScript enforces strict type checking on the^ operator to prevent unintended runtime coercion:
Number and Enum Operands:
Operands can be of type number, any, or a numeric enum.
^ operator fully supports bigint types. Because bigint operates at arbitrary precision, no 32-bit truncation occurs.
ts(2365) error if you attempt to mix number (or enum) and bigint operands, as the underlying JavaScript engine cannot implicitly mix these types for bitwise operations.
Compound Assignment
TypeScript supports the compound assignment operator^=, which applies the bitwise XOR operation and assigns the resulting value back to the left operand.
Master TypeScript with Deep Grasping Methodology!Learn More





