TypeError:无法混合 BigInt 和其他类型,使用显式转换

Man*_*rma 12 javascript random ecmascript-2016

我正在尝试生成一个 20 位随机数:

let code = Math.floor(10000000000000000000n + Math.random() * 90000000000000000000n)
Run Code Online (Sandbox Code Playgroud)

我尝试过输入数字BigInt()以及添加n后,但仍然出现此错误。

Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions
Run Code Online (Sandbox Code Playgroud)

Liu*_*Lei 10

// An operation with a fractional result will be truncated when used with a BigInt.\n\nconst rounded = 5n / 2n\n// \xe2\x86\xaa 2n, not 2.5n\n\n// BigInt value can only operator with same type\n\n// random BigInt\nBigInt(Math.floor(Math.random() * 10))\n\n// generate a 20 digit random number\nBigInt(Math.floor(Math.random() * 100000000000000000000))\n
Run Code Online (Sandbox Code Playgroud)\n

你可以检查这个

\n