Advertisement
Advertisement


How can I use modulo operator (%) in JavaScript?


Question

How can I use modulo operator (%) in calculation of numbers for JavaScript projects?

2017/07/23
1
123
7/23/2017 3:47:04 PM

Accepted Answer

It's the remainder operator and is used to get the remainder after integer division. Lots of languages have it. For example:

10 % 3 // = 1 ; because 3 * 3 gets you 9, and 10 - 9 is 1.

Apparently it is not the same as the modulo operator entirely.

2014/08/20
202
8/20/2014 5:30:14 PM

That would be the modulo operator, which produces the remainder of the division of two numbers.

2013/05/12