BigInt
Integers of any size, without loss of precision.
Available since: ES2020
Syntax
BigInt(value)Parameters
| Parameter | Type | Description |
|---|---|---|
| value | number | string | An 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:
18446744073709551616Regular numbers lose precision, BigInt does not:
console.log(9007199254740993);
console.log(9007199254740993n);
console.log(typeof 10n);Output:
9007199254740992
9007199254740993
bigintNotes
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
- Number.MAX_SAFE_INTEGER — The largest integer that is stored without losing precision.
- Number.isSafeInteger — Checks that an integer is within the range where it is stored exactly.
- typeof — Returns a string with the type of a value.
Related recipes
In the tutorial
- Data types — The main JavaScript data types — numbers, strings, booleans, null and undefined, and the typeof operator.