Suggest an editImprove this articleRefine the answer for “What is the bigint type?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)The `bigint` type is a **primitive numeric type** designed for working with **integers of arbitrary length**, that is, numbers so large they **do not fit** into the standard `number` type. **Key point:** it appeared in ECMAScript 2020 (ES11) and has been supported in TypeScript since version 3.2.Shown above the full answer for quick recall.Answer (EN)ImageThe `bigint` type is a **primitive numeric type** designed for working with **integers of arbitrary length**, that is, numbers so large they **do not fit** into the standard `number` type. It appeared in **ECMAScript 2020 (ES11)** and has been supported in TypeScript since version **3.2**. --- ### Features of the `bigint` type 1. Represents **only integers** (no fractional part). 2. Can store numbers that **go beyond the safe range** of `number` (`Number.MAX_SAFE_INTEGER` = 2^53 - 1). 3. Has **its own syntax**: `bigint` literals end with the letter `n`. ```javascript let big: bigint = 123456789012345678901234567890n; ``` --- ### How to declare a variable of type `bigint` #### 1. Via a literal with `n`: ```javascript let id: bigint = 9007199254740993n; // larger than the safe number ``` #### 2. Via the `BigInt()` constructor: ```javascript let bigFromString: bigint = BigInt("9007199254740993000000000000000"); let bigFromNumber: bigint = BigInt(123); ``` --- ### Comparison with the `number` type | Characteristic | `number` | `bigint` | |---|---|---| | Range | up to +-9,007,199,254,740,991 (`2^53 - 1`) | No limits | | Number type | Floating-point (float) | Integers only | | Performance | Faster | Slower | | Arithmetic | Can mix fractional and integer values | Integers only | | Compatibility | Works with most JS APIs | Some APIs do not support it | | Mixing types | Cannot mix with `bigint` | Error on `bigint + number` | Example: ```javascript let a: number = 10; let b: bigint = 20n; // console.log(a + b); // Error: cannot mix number and bigint console.log(BigInt(a) + b); // Convert number to bigint ``` --- ### Examples of operations with `bigint` ```javascript let bigA = 123456789012345678901234567890n; let bigB = 10n; console.log(bigA + bigB); // 123456789012345678901234567900n console.log(bigA - bigB); // 123456789012345678901234567880n console.log(bigB ** 5n); // 100000n console.log(bigA % bigB); // 0n ``` --- ### Important limitations 1. `bigint` **cannot be used** with `Math`: ```javascript Math.sqrt(16n); // Error ``` 2. `bigint` **cannot be mixed with** `number` **directly**: ```javascript 10n + 5; // Error ``` 3. For comparison (`<`, `>`, `==`) it works, but `===` requires matching types: ```javascript 5n == 5; // true 5n === 5; // false ``` --- ### When to use `bigint` Use `bigint` when: 1. You need to work with **large integers** that exceed the `number` range: - cryptography, hashing - financial calculations with large sums - working with identifiers (ID, timestamp) - counters that could overflow 2. You need **precision** rather than computation speed. --- ### Example of a precision comparison ```javascript let normal = 9007199254740991; // MAX_SAFE_INTEGER console.log(normal + 1); // 9007199254740992 console.log(normal + 2); // 9007199254740992 (precision is lost) let big = 9007199254740991n; console.log(big + 1n); // 9007199254740992n console.log(big + 2n); // 9007199254740993n ```For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.