我怎么能过33!在浏览器中使用 Javascript?

How can I get past 33! using Javascript in Browser?

我知道一定是我漏了一个技巧,我怎么计算过去的33!在浏览器 JS 中使用?我有 following already,这让我达到了 33,但是当我达到 34 时就崩溃了。我有 34 可以像这样在 Node 中工作...

 node --max-old-space-size=4096 --experimental-modules test.mjs

但它在 35 时再次爆炸。

我可以算过去33吗!在浏览器中使用 JS?

本机不支持如此大的数字,因此一种选择是使用库,例如​​ BigInteger:

const factorial = n => bigInt(n).multiply(
  n === 1
  ? 1
  : factorial(n - 1)
);
console.log(factorial(45));
<script src="https://cdnjs.cloudflare.com/ajax/libs/big-integer/1.6.34/BigInteger.min.js"></script>

(使用时,确保将大数字作为 字符串 或其他 bigInt 传递,以避免精度损失)