Suggest an editImprove this articleRefine the answer for “What is BigInt?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**`BigInt`** is a special data type in JavaScript designed for working with very large integers that go beyond the limits of the standard `Number` type. **Key point:** `BigInt` lets you work with integers of any length without losing precision.Shown above the full answer for quick recall.Answer (EN)Image## What is BigInt `BigInt` is a **special data type** in JavaScript designed for working with **very large integers** that go beyond the limits of the standard `Number` type. Regular numbers (`Number`) in JS are stored as **64-bit IEEE-754 values**, and the maximum safe integer that can be represented exactly is: ```javascript Number.MAX_SAFE_INTEGER; // 9007199254740991 (≈ 9 * 10^15) ``` If you exceed this limit, JavaScript starts **losing precision**: ```javascript console.log(9007199254740991 + 1); // 9007199254740992 (correct) console.log(9007199254740991 + 2); // 9007199254740992 (wrong!) ``` --- ## BigInt solves this problem `BigInt` lets you work with **integers of any length**, without losing precision: ```javascript const big = 9007199254740991n; // a BigInt literal (note the 'n' at the end) console.log(big + 2n); // 9007199254740993n ``` The `n` suffix at the end of a number makes it a BigInt. You can also create one through the constructor: ```javascript const big = BigInt("900719925474099312345678901234567890"); ``` --- ## Main properties of BigInt | Feature | Example | |---|---| | Created with `n` or `BigInt()` | `123n` or `BigInt(123)` | | Supports arithmetic (`+`, `-`, `*`, `/`, `%`) | `100n + 200n` → `300n` | | Division is **integer only** | `5n / 2n` → `2n` (the remainder is dropped) | | Cannot be mixed with regular numbers (`Number`) directly | `1n + 1` throws an error | | Can be converted explicitly | `Number(1n)` or `BigInt(1)` | | Works with comparison operators | `2n > 1n` | | Works with `===`, but is not equal to `Number` | `1n === 1` → `false` | --- ## Example of an error when mixing types ```javascript const big = 10n; const num = 5; console.log(big + num); // TypeError ``` Correct: ```javascript console.log(big + BigInt(num)); // 15n ``` or ```javascript console.log(Number(big) + num); // 15 ``` --- ## Usage examples 1. **Cryptography, hashes, large keys** ```javascript const key = 1234567890123456789012345678901234567890n; const mod = 99999999999999999999999999999999999n; console.log(key % mod); ``` 2. **Financial calculations that need precision** ```javascript const price = 10000000000000000000n; // an exact sum with no rounding errors ``` 3. **Working with very large counters** ```javascript let counter = 0n; for (let i = 0n; i < 1_000_000_000_000_000_000n; i++) { counter++; } ``` --- ## Checking the type ```javascript typeof 123n; // "bigint" ``` --- ## Summary | Key fact | Value | |---|---| | Data type | `bigint` | | What it's for | Working with integers > `Number.MAX_SAFE_INTEGER` | | Creation | `123n` or `BigInt(123)` | | Feature | Full precision, integers only | | Incompatible with Number | you have to convert types manually | | Division | Integer only |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.