Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

BigInt — exact integers

BigInt(value) creates a bigint primitive for exact integer arithmetic beyond the safe Number range. Learn how conversion works, which arithmetic restrictions apply, and how to produce text with toString(radix).

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

BigInt(value)
123n
value.toString(radix)

BigInt(value) returns a primitive of type bigint, representing an arbitrary-precision integer within implementation resource limits. A literal with the n suffix, such as 123n, is an alternative. The function and literals belong to ECMAScript 2020, not Web APIs. new BigInt(1) throws TypeError. The language specification is not a browser compatibility table; Node 24 in a repository does not establish browser support.

For large values, use text, such as BigInt("9007199254740993"): conversion cannot undo earlier rounding of a Number value. BigInt(1.5) throws RangeError, and invalid integer text throws SyntaxError. Converting true produces 1n, while false produces 0n.

Arithmetic requires matching types: 1n + 1 throws TypeError, whereas 1n + 1n produces 2n. Integer division truncates the fractional part toward zero: 7n / 2n produces 3n. Conversion through Number(value) can lose precision.

Distinguish the label BigInt.toString from the value method: the actual API is BigInt.prototype.toString, called as value.toString(radix). BigInt.toString() describes the function itself rather than formatting an integer. The value method returns text without the n suffix; the default radix is 10. Before checking the range, the method converts radix to an integer, truncating any fractional part toward zero. If the converted value is outside 2 through 36 inclusive, the method throws RangeError. For example, (255n).toString(36.9) uses radix 36 and returns "73".

Examples

const value = BigInt("9007199254740993");
const next = value + 2n;
console.log(typeof value);
console.log(next.toString());
console.log((255n).toString(16));
console.log((7n / 2n).toString());

Result

bigint
9007199254740995
ff
3

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources