取余 (%)

翻译不完整。 请帮助我们翻译这篇文章!

当一个操作数除以第二个操作数时,取余运算符(%)返回剩余的余数。它与被除数的符号保持一致。

语法

Operator: var1 % var2

示例

被除数为正数

 12 % 5  //  2
 1 % -2 //  1
 1 % 2  //  1
 2 % 3  //  2
5.5 % 2 // 1.5

被除数为负数

-12 % 5 // -2
-1 % 2  // -1
-4 % 2  // -0

被除数为NaN

NaN % 2 // NaN

规范

Specification
ECMAScript (ECMA-262)
Remainder operator

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Remainder (%)Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100

Legend

Full support  
Full support

相关链接