%在JavaScript中做什么? [英] What does % do in JavaScript?

查看:126
本文介绍了%在JavaScript中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

%在JavaScript中做了什么?

What does the % do in JavaScript?

对它的定义及其作用将非常感激。

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

推荐答案

这是 模运算符 即可。请参阅 文档 < a href =http://www.ecma-international.org/ecma-262/6.0/index.html#sec-applying-the-mod-operator =noreferrer>规范 有关JavaScript算术运算符的更多信息。

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


%(模数)

模数运算符的用法如下:

The modulus operator is used as follows:

var1%var2

var1 % var2

模数运算符在前面的语句中返回第二个
操作数的第一个操作数,即var1 modulo var2,其中
var1和var2是变量。模数函数是将var1除以var2的整数
余数。例如,12%5返回2.
结果将与var1具有相同的符号;也就是说,-1%2返回-1。

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.

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

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