A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/BigInt_division_by_zero below:

RangeError: BigInt division by zero - JavaScript

RangeError: BigInt division by zero

The JavaScript exception "BigInt division by zero" occurs when a BigInt is divided by 0n.

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

RangeError.

What went wrong?

The divisor of a division or remainder operator is 0n. In Number arithmetic, this produces Infinity, but there's no "infinity value" in BigInts, so an error is issued. Check if the divisor is 0n before doing the division.

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

Instead, check if the divisor is 0n first, and either issue an error with a better message, or fallback to a different value, like Infinity or undefined.

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4