CKTIS / JavaScript
Remainder operator (%)
The % operator computes a remainder for Number or BigInt values. A nonzero result has the dividend's sign, so negative inputs distinguish remainder from nonnegative modulo. Operand types and division by zero need special attention.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
dividend % divisorIn dividend % divisor, the left operand is the dividend and the right operand is the divisor. For finite values and a nonzero divisor, the remainder corresponds to subtracting the divisor multiplied by the quotient truncated toward zero from the dividend. A nonzero result has the dividend's sign: -13 % 5 is -3, whereas 13 % -5 is 3. % does not mean percentage.
Remainder is not the same as nonnegative modulo. For integer Number values within the safe range and a positive divisor, normalize with ((dividend % divisor) + divisor) % divisor; also account for the safe range of the intermediate sum. For -13 and 5, this produces 2.
Operands are converted to numeric values; after conversion, both must be Number or both must be BigInt. Mixing these types throws TypeError. Number permits fractions, for example 5.5 % 2 is 1.5, but is subject to floating-point precision limitations. BigInt operates on integers.
For Number, a divisor of 0 or -0, a NaN operand, or an infinite dividend produces NaN. A finite dividend with an infinite divisor is returned unchanged. A negative dividend can produce -0, detectable with Object.is(result, -0). For BigInt, a divisor of 0n throws RangeError; this type has no -0.
% has the same precedence as * and /, higher than + and -; operators in this group associate left to right. It belongs to the ECMAScript language, not a Web API. The example requires an environment supporting BigInt.
Examples
const dividend = -13;
const divisor = 5;
console.log(dividend % divisor);
console.log(((dividend % divisor) + divisor) % divisor);
console.log(5.5 % 2);
console.log(String(13n % 5n));
console.log(Object.is(-10 % 5, -0));
console.log(Number.isNaN(10 % 0));Result
-3 2 1.5 3 true true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.