Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

RangeError: BigInt division by zero

The JavaScript exception "BigInt division by zero" occurs when aBigInt is divided by0n.

Message

RangeError: Division by zero (V8-based)RangeError: BigInt division by zero (Firefox)RangeError: 0 is an invalid divisor value. (Safari)

Error type

What went wrong?

The divisor of adivision orremainder operator is0n. InNumber arithmetic, this producesInfinity, but there's no "infinity value" in BigInts, so an error is issued. Check if the divisor is0n before doing the division.

Examples

Division by 0n

js
const a = 1n;const b = 0n;const quotient = a / b;// RangeError: BigInt division by zero

Instead, check if the divisor is0n first, and either issue an error with a better message, or fallback to a different value, likeInfinity orundefined.

js
const a = 1n;const b = 0n;const quotient = b === 0n ? undefined : a / b;

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp