JavaScript % Remainder Operator
The remainder operator (%) returns what is left over after dividing one number by another. It's often used to check for even numbers or to wrap values around.
Description
The remainder operator % returns the remainder left over when the left operand is divided by the right. The result has the sign of the left operand, so -7 % 3 is -1; it's a remainder, not a true modulo. To wrap negative values into a range, use ((n % m) + m) % m.
Common uses are checking for even or odd numbers (n % 2 === 0), doing something every nth time, and cycling through items.
For floating point operands, the remainder can be a decimal: 5.5 % 2 is 1.5. Taking a remainder by zero gives NaN, and with BigInts it throws a RangeError. The remainder operator has the same precedence as multiplication and division.
Properties
- Operator
%- Category
- Arithmetic
- Precedence
- 12 (1 is lowest, 18 is highest)
- Associativity
- left-to-right
Syntax
x % yExample
Browser Support
The following information will show you the current browser support for the % operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





