Skip to content
Related Articles

Related Articles

JavaScript | BigInt.prototype.toString() Method

View Discussion
Improve Article
Save Article
  • Last Updated : 18 Nov, 2021
View Discussion
Improve Article
Save Article

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: 
 

javascript




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

Output: 
 

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

Example 2: 
 

javascript




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

Output: 
 

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

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
     
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!