Big Factorial (BigInt)
Compute n! up to 1000 with BigInt and show full result + digit count.
Large factorials with BigInt
Factorials blow up fast. By 13! you've already cleared 2³² (Int32 overflow), and 21! sails past 2⁶⁴ (Int64 overflow). The catch in JavaScript is that the Number type is a 64-bit float, which stops being exact once you go above Number.MAX_SAFE_INTEGER = 2⁵³ − 1. That's what BigInt solves. It's been part of the language since ES2020 and gives you arbitrary-precision integers, written with an n suffix (10n). Computing the value is nothing fancy — a loop over a BigInt accumulator: let r = 1n; for (let i = 2n; i <= BigInt(n); i++) r *= i;. If you just want a sense of the size, Stirling's approximation does the job: n! ≈ √(2πn)·(n/e)ⁿ. To put numbers on it, 100! runs to 158 digits and 1000! to 2,568.
Applications and context
You'll run into this in cryptography, where RSA does modular arithmetic on enormous integers, and in theoretical combinatorics, where a brute-force TSP is O(n!). It also shows up in combinatorial analysis in ML when you're counting permutations of features, in large counters backed by BigInt columns in databases, and across competitive programming — plenty of Codeforces and Project Euler problems have answers that simply won't fit in 64 bits.
FAQ
Why not use Number for large factorials? Once you pass 2⁵³ the results get rounded, so the trailing digits come out wrong. BigInt keeps every digit exact.
How slow is BigInt? Multiplying an N-digit number costs O(N), or O(N log N) on engines that fall back to FFT. In practice, modern V8 computes 1000! in a few milliseconds.
Can I mix BigInt with Number? No. JavaScript throws a TypeError if you try. You have to convert first, with BigInt(x) or Number(b).
Related Tools
Rent Adjustment Calculator
Compute annual rent adjustment by IGP-M or IPCA accumulated in the last 12 months (manually configurable).
Pregnancy Calculator
Compute estimated due date (EDD), gestational age and trimester from the last menstrual period (LMP).
Fertile Period Calculator
Compute fertile window and ovulation day from the first day of the last cycle and the average cycle length.