JavaScript | BigInt.prototype.toString() Method

The BigInt.prototype.toString() method is an inbuilt method in JavaScript which is used to return a string representing the specified BigInt object.

Syntax:

bigIntObj.toString( radix )

Parameters: This function accepts single parameter and it is an optional.

  • radix: It is an integer value in the range 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.



Below examples illustrate the BigInt.prototype.toString() method in JavaScript:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

console.log(1023n.toString());
  
console.log(1023n.toString(2));
  
console.log(1023n.toString(9));
  
console.log((-0n).toString());   
  
console.log(BigInt(-0).toString());

chevron_right


Output:

"1023"
"1111111111"
"1356"
"0"
"0"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

console.log(17n.toString());
  
console.log(66n.toString(2));
  
console.log(254n.toString(16));   
  
console.log(-10n.toString(2));
  
console.log(-0xffn.toString(2));

chevron_right


Output:

"17"
"1000010"
"fe"
-1010
-11111111

Supported Browsers: The browsers supported by BigInt.prototype.toString() method are listed below:

  • Google Chrome
  • Firefox
  • Opera
  • Safari
  • Edge

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.