BigInt: Arbitrary-Precision Integers
What you'll learn: How JavaScript's BigInt type lets you work with whole numbers far bigger than the regular Number type can handle.
Why BigInt Exists
Remember how the Number type has limits? The largest safe integer you can reliably work with is 9,007,199,254,740,991 (about 9 quadrillion). Beyond that, Numbers start losing precision because they're stored as floating-point values.
BigInt solves this problem. It's a special primitive type designed specifically for integers that can be arbitrarily large—as big as your computer's memory allows. Think of it like the difference between a calculator with a fixed display (Number) versus one with an infinite paper tape (BigInt).
Creating a BigInt
You create a BigInt by adding the letter n to the end of an integer:
const regularNumber = 123;
const bigInteger = 123n;
That n tells JavaScript: "This is a BigInt, not a Number."
When You Need BigInt
BigInt is essential for:
- Working with very large whole numbers (cryptocurrency calculations, scientific computing)
- Situations requiring exact integer precision beyond Number's safe range
- Problems where even one digit of error is unacceptable
Important Distinction
BigInt and Number are separate types. They don't mix directly—you can't add a BigInt to a regular Number without converting one of them first. They're like two different number systems that don't automatically translate.
Key Takeaway: BigInt is JavaScript's newest primitive type, enabling precise calculations with arbitrarily large integers by appending n to whole numbers—critical when Number's floating-point limitations aren't acceptable.