← 返回首页
除法(/) - JavaScript | MDN

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

除法(/)

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

除法/)运算符计算两个操作数的商,其中左操作数是被除数,右操作数是除数。

本文内容

尝试一下

console.log(12 / 2); // Expected output: 6 console.log(3 / 2); // Expected output: 1.5 console.log(6 / "3"); // Expected output: 2 console.log(2 / 0); // Expected output: Infinity

语法

js
x / y

示例

基本除法

js
1 / 2; // 0.5 Math.floor(3 / 2); // 1 1.0 / 2.0; // 0.5

除以零

js
2.0 / 0; // Infinity 2.0 / 0.0; // Infinity, because 0.0 === 0 2.0 / -0.0; // -Infinity

规范

规范
ECMAScript® 2027 Language Specification
# sec-multiplicative-operators

浏览器兼容性

启用 JavaScript 以查看此浏览器兼容性表。

参见