JavaScript BigInt()
The BigInt() Function
The BigInt() function creates BigInt values.
BigInt values can represent integers larger than JavaScript's safe integer range.
BigInt is a primitive data type.
Creating a BigInt
Examples
Literal Syntax
let x = 123n;
Try it Yourself »
Function Syntax
let x = BigInt(123);
Try it Yourself »
Syntax
BigInt(value)
Parameters
| Parameter | Description |
|---|---|
| value | A value to convert to a bigint. |
Return Value
| Type | Returns |
|---|---|
| BigInt | A primitive bigint value. |
BigInt Type
The type of a bigint value is "bigint".
Large Integers
BigInt values can safely represent very large integers.
BigInt vs Number
| BigInt | Number |
|---|---|
| Arbitrary-size integers | 64-bit floating-point values |
| Primitive type is bigint | Primitive type is number |
| No decimal values | Supports decimals |
Conversion
| Expression | Result |
|---|---|
BigInt(123) |
123n |
BigInt("123") |
123n |
Important Warning
BigInt values cannot be mixed directly with Number values.
Example
const x = 10n;
const y = 5;
x + y; // Error
No Constructor
BigInt is not a constructor.
The new keyword cannot be used with BigInt.
Example
new BigInt(123); // TypeError
| What | Value |
|---|---|
| Callable | Yes |
| Constructible | No |
| Returns | Primitive bigint values |
| Primitive Type | bigint |
Primitives Compared
| Function | Constructible |
|---|---|
| String() | Yes |
| Number() | Yes |
| Boolean() | Yes |
| BigInt() | No |
| Symbol() | No |
Browser Support
BigInt() is a JavaScript 2020 feature.
ES 2020 is supported in all modern browsers since September 2020:
| Chrome 85 |
Edge 85 |
Firefox 79 |
Safari 14 |
Opera 71 |
| Aug 2020 | Aug 2020 | Mar 2020 | Sep 2020 | Sep 2020 |