Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
71
rated 0 times [  76] [ 5]  / answers: 1 / hits: 25409  / 13 Years ago, tue, january 17, 2012, 12:00:00

What does the % do in JavaScript?



A definition of what it is and what it does would be much appreciated.


More From » javascript

 Answers
22

It's a modulo operator. See this documentation or the specification for more information on JavaScript arithmetic operators.




% (Modulus)



The modulus operator is used as follows:



var1 % var2



The modulus operator returns the first operand modulo the second
operand, that is, var1 modulo var2, in the preceding statement, where
var1 and var2 are variables. The modulo function is the integer
remainder of dividing var1 by var2. For example, 12 % 5 returns 2. The
result will have the same sign as var1; that is, −1 % 2 returns −1.



[#87964] Monday, January 16, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
theodore

Total Points: 318
Total Questions: 97
Total Answers: 119

Location: Turks and Caicos Islands
Member since Sun, Mar 7, 2021
3 Years ago
;