Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Division (/)

BaselineWidely available

Thedivision (/) operator produces the quotient of its operands where the left operand is the dividend and the right operand is the divisor.

Try it

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

Syntax

js
x / y

Description

The/ operator is overloaded for two types of operands: number andBigInt. It firstcoerces both operands to numeric values and tests the types of them. It performs BigInt division if both operands become BigInts; otherwise, it performs number division. ATypeError is thrown if one operand becomes a BigInt but the other becomes a number.

For BigInt division, the result is the quotient of the two operands truncated towards zero, and the remainder is discarded. ARangeError is thrown if the divisory is0n. This is because number division by zero returnsInfinity or-Infinity, but BigInt has no concept of infinity.

Examples

Division using numbers

js
1 / 2; // 0.5Math.floor(3 / 2); // 11.0 / 2.0; // 0.52 / 0; // Infinity2.0 / 0.0; // Infinity, because 0.0 === 02.0 / -0.0; // -Infinity

Other non-BigInt values are coerced to numbers:

js
5 / "2"; // 2.55 / "foo"; // NaN

Division using BigInts

js
1n / 2n; // 0n5n / 3n; // 1n-1n / 3n; // 0n1n / -3n; // 0n2n / 0n; // RangeError: BigInt division by zero

You cannot mix BigInt and number operands in division.

js
2n / 2; // TypeError: Cannot mix BigInt and other types, use explicit conversions2 / 2n; // TypeError: Cannot mix BigInt and other types, use explicit conversions

To do division with a BigInt and a non-BigInt, convert either operand:

js
2n / BigInt(2); // 1nNumber(2n) / 2; // 1

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-multiplicative-operators

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp