What is the modulo operator in JavaScript?

The modulo operator is represented by the % character in JavaScript. It returns the remainder of two integers that have been divided.

svg viewer
remainder = 7 % 5
console.log(remainder)

As the remainder will always be less than the divisor, modulo operators can be very useful in restricting the range of outputs. This makes modulo operators particularly popular in Hash functions.

for(var i=0; i<10; i+=1)
{
console.log( i % 4 ) //As divisor is 4, remainder will range from 0 to 3
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
šŸ† Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved