The BigInt.toString() method is an inbuilt method in JavaScript that is used to return a string representing the specified BigInt object.
Syntax:
bigIntObj.toString( radix )
Parameters: This function accepts a single parameter and it is optional.
- radix: It is an integer value in the range of 2 through 36.
Return value: This method returns a string representing the specified BigInt object.
Exceptions: A RangeError is thrown if the toString() is less than 2 or greater than 36 in the radix.
The below examples illustrate the BigInt.prototype.toString() method in JavaScript:
Example 1: This example shows the use of the BigInt.prototype.toString() method in JavaScript.
javascript
<script> console.log(1023n.toString()); console.log(1023n.toString(2)); console.log(1023n.toString(9)); console.log((-0n).toString()); console.log(BigInt(-0).toString()); </script> |
Output:
"1023" "1111111111" "1356" "0" "0"
Example 2: This example shows the use of the BigInt.prototype.toString() method in JavaScript.
javascript
<script> console.log(17n.toString()); console.log(66n.toString(2)); console.log(254n.toString(16)); console.log(-10n.toString(2)); console.log(-0xffn.toString(2)); </script> |
Output:
"17" "1000010" "fe" -1010 -11111111
We have a complete list of Javascript BigInt Methods, to check those please go through the Javascript BigInt Complete Reference article.
Supported Browsers: The browsers supported by BigInt.prototype.toString() method are listed below:
- Google Chrome 67 and above
- Edge 79 and above
- Firefox 68 and above
- Opera 54 and above
- Safari 14 and above