BigInt() function returns a value of type bigint.
The numeric value of the object being created. It may be a string, an integer, a boolean, or another
BigInt value. Number values must be integers and are converted to BigInts. The boolean value
0n. Strings are parsed as if they are source text for integer literals, which means they can have leading and trailing whitespaces and can be prefixed with
Thrown if the parameter is a non-integral number.
Thrown if at least one of these conditions is met:
Thrown if the parameter is a string that cannot be parsed as a
BigInt() is the only case where a number can be converted to a BigInt without throwing, because it's very explicit. However, only integers are allowed.
BigInt(123); // 123n BigInt(123.3); // RangeError: The number 123.3 cannot be converted to a BigInt because it is not an integer
BigInt("123"); // 123n BigInt("0b10101"); // 4161n, which is 10101 in binary BigInt("0o123"); // 83n, which is 123 in octal BigInt("0x123"); // 291n, which is 123 in hexadecimal BigInt(" 123 "); // 123n, leading and trailing whitespaces are allowed
|ECMAScript Language Specification |
BCD tables only load in the browser