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.
~ (Bitwise NOT) operator is a unary operator that performs bitwise inversion on its operand. For standard numbers, it coerces the evaluated operand into a 32-bit signed integer and yields the two’s complement inverse by flipping every 0 to 1 and every 1 to 0. For bigint operands, it performs arbitrary-precision bitwise inversion without 32-bit truncation, returning a bigint.
Execution Mechanics
When the TypeScript compiler and underlying JavaScript engine process the~ operator, the execution path diverges based on the evaluated type of the operand:
For number and non-bigint types:
- Evaluation and Coercion: The
expressionis evaluated. Non-numeric values undergo standard ECMAScript type coercion to anumber(e.g.,nullbecomes0,undefinedbecomesNaN). ToInt32Conversion: The numeric value is cast to a 32-bit signed integer using two’s complement representation. Floating-point numbers are truncated to integers. AnyNaNorInfinityvalues are converted to0.- Bitwise Inversion: Every bit in the 32-bit sequence is inverted.
- Return: The resulting 32-bit binary sequence is returned as a standard
number.
bigint types:
- Evaluation: The
expressionis evaluated as abigint. - Arbitrary-Precision Inversion: The operator computes the bitwise NOT of the arbitrary-precision integer. It conceptually treats the
bigintas a two’s complement binary representation with an infinite number of leading sign bits, flipping all bits without applying any 32-bit truncation. - Return: The inverted value is returned as a
bigint.
x, the operation ~x evaluates to -(x + 1).
Syntax and Behavior Visualization
as any type assertion is grouped within parentheses to bypass TypeScript’s static type checker before the unary operator is applied. TypeScript intentionally flags bitwise operations on non-numeric types as errors to enforce type safety, though the runtime mechanics remain identical to standard ECMAScript behavior.
Master TypeScript with Deep Grasping Methodology!Learn More





