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.
%= (remainder assignment) operator divides the value of the left operand (dividend) by the value of the right operand (divisor) and assigns the resulting remainder to the left operand. As a compound assignment operator, it evaluates the left-hand side reference only once, distinguishing it from a standard assignment combined with a modulo operation.
Mechanics
- Evaluation: The left operand is evaluated first to resolve its reference and retrieve its value. Then, the right operand is evaluated.
- Calculation: The JavaScript engine performs a truncated division (rounding towards zero) of the left operand’s value by the right operand’s value to determine the remainder.
- Sign Preservation: The sign of the returned remainder strictly matches the sign of the dividend (the left operand), regardless of the sign of the divisor.
- Assignment: The computed remainder is written back to the resolved memory location of the left operand.
TypeScript Type Constraints
TypeScript enforces strict type checking on the%= operator:
- Valid Types: Both operands must resolve to
numberorbigint. - Type Homogeneity: You cannot mix
numberandbigintoperands. Doing so results in ats(2365)compiler error. - Mutability: The left operand must be a valid l-value (a mutable reference, such as a variable declared with
letor a writable object property). It cannot be aconst.
Syntax and Behavior Examples
Standard Numeric Evaluation:%= behaves differently than x = x % y when the left operand contains side effects.
Edge Cases (IEEE 754 Floating Point)
Because TypeScriptnumber types are double-precision 64-bit floats, the operator handles specific edge cases according to the IEEE 754 standard:
- If the dividend is
Infinityor-Infinity, the result isNaN. - If the divisor is
0or-0, the result isNaN. - If the dividend is
0and the divisor is non-zero, the result is0.
Master TypeScript with Deep Grasping Methodology!Learn More





