JavaScript中的%运算符是什么? [英] What is the % operator in JavaScript?
问题描述
我正在尝试解密一段JS代码(而(显然)我的JS知识为空).
以下代码中的%运算符是什么?
I am trying to decipher a piece of JS code (while (obviously) my JS knowledge is null).
What is the % operator in the code below?
m[p1%2][q1] = 0.0;
for(j=q1+1; j <= q2; j++)
m[p1%2][j] = m[p1%2][j-1] + 1;
推荐答案
%
is remainder operator. It gives the remainder after division.
Quoting from MDN
一个操作数除以第二个操作数时,余数运算符返回剩余的余数.它总是采用除数的符号,而不是除数的符号.它使用内置的模函数来生成结果,该结果是将
var1
除以var2
的整数余数-例如,- var1模var2 .
The remainder operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend, not the divisor. It uses a built-in modulo function to produce the result, which is the integer remainder of dividing
var1
byvar2
— for example — var1 modulo var2.
有人建议在ECMAScript的未来版本中使用实际的模运算符,区别在于模运算符结果将采用除数的符号,而不是除数.
这篇关于JavaScript中的%运算符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!