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 the remainder operator. It evaluates to the remainder left over when one operand (the dividend) is divided by a second operand (the divisor). Crucially, in JavaScript, this is a remainder operation rather than a strict mathematical modulo operation. This distinction dictates that the sign of the result always matches the sign of the dividend, regardless of the divisor’s sign.
Mathematical Evaluation
Internally, JavaScript evaluatesn % d using the following formula:
r = n - (d * q)
where q is the quotient of n / d truncated towards zero (equivalent to Math.trunc(n / d)).
Sign Behavior
Because the quotient is truncated towards zero, the remainder inherits the sign of the left operand (the dividend).Floating-Point Operands
Unlike languages that restrict the remainder operator to integers, JavaScript applies IEEE 754 double-precision floating-point arithmetic to the% operator. It computes the exact remainder of floating-point division.
BigInt Operands
The% operator fully supports BigInt operands. The mathematical evaluation remains identical, but the edge-case behavior for division by zero differs strictly from standard Number types.
Edge Cases and Special Values (Numbers)
When operating on standardNumber types, the operator adheres to specific IEEE 754 rules when encountering 0, Infinity, or NaN:
Type Coercion
If either operand is not a numeric type, JavaScript implicitly coerces it using the internalToNumeric() abstract operation before evaluating the remainder.
If the resulting types do not match (e.g., one operand evaluates to a BigInt and the other to a Number), JavaScript does not coerce them to a common numeric type. Instead, it throws a TypeError.
Master JavaScript with Deep Grasping Methodology!Learn More





