The modulo operator is represented by the %
character in JavaScript. It returns the remainder of two integers that have been divided.
remainder = 7 % 5console.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}
Free Resources