JS: bigint constructor
BigInt() constructor
// string to bigint const xbig1 = BigInt("123456789012345678901234567890"); console.log( xbig1 ) // 123456789012345678901234567890n // number to bigint. the number must be less than Number.MAX_SAFE_INTEGER const xbig2 = BigInt(123); console.log( xbig2 ) // 123n console.log( Number.MAX_SAFE_INTEGER ) // 9007199254740991
- You cannot pass a floating-point number or a string with decimals to
BigInt()— it throws an error. BigInt(1.5)→ TypeErrorBigInt("1.5")→ SyntaxError (in constructor) or TypeError