Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

BigInt

Integers of any size, without loss of precision.

Available since: ES2020

Syntax

BigInt(value)

Parameters

ParameterTypeDescription
valuenumber | stringAn integer or a string containing one.

Return value

bigintAn integer of any size.

Examples

A literal with n at the end:

console.log(2n ** 64n);

Output:

18446744073709551616

Regular numbers lose precision, BigInt does not:

console.log(9007199254740993);
console.log(9007199254740993n);
console.log(typeof 10n);

Output:

9007199254740992
9007199254740993
bigint

Notes

BigInt and regular numbers cannot be mixed in arithmetic: 10n + 1 throws a TypeError. Convert explicitly: 10n + BigInt(1). BigInt division drops the fraction: 7n / 2n is 3n.

See also

Related recipes

In the tutorial

  • Data types — The main JavaScript data types — numbers, strings, booleans, null and undefined, and the typeof operator.

Thanks for reading!

Donate to the site — we work hard for you.