Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Remainder assignment (%=)

The %= operator calculates the remainder of the current value divided by the right operand and stores the result in the same target. It supports Number and BigInt; remainder is not the same as always-nonnegative modulo.

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

target %= expression

The operator target %= expression reads the target's value, calculates the remainder after division by the right operand, and assigns the result to the target. The expression itself returns the assigned value. For a simple variable, x %= y works like x = x % y, but the left-hand target is evaluated only once—important for property access with side effects.

% means remainder, not always-nonnegative modulo: -17 % 5 produces -2. A nonzero remainder has the dividend's sign. For Number, the result can also be -0; a zero divisor produces NaN.

Operands undergo numeric conversion; both must ultimately be Number values or both BigInt values. Mixing these types throws TypeError. If both operands are BigInt values, a divisor of 0n throws RangeError. The target must allow writing: assigning to a variable declared with const throws TypeError.

The example demonstrates positive and negative remainders and the BigInt variant. String(large) ensures consistent result formatting regardless of how the console displays BigInt values.

Examples

let value = 17;
value %= 5;
console.log(value);

let negative = -17;
negative %= 5;
console.log(negative);

let large = 17n;
large %= 5n;
console.log(String(large));

Result

2
-2
2

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources