JavaScript中的%运算符是什么? [英] What is the % operator in JavaScript?

查看:104
本文介绍了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 by var2 — for example — var1 modulo var2.

有人建议在ECMAScript的未来版本中使用实际的模运算符区别在于模运算符结果将采用除数的符号,而不是除数.

这篇关于JavaScript中的%运算符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆