Skip to content
Related Articles

Related Articles

Improve Article
JavaScript | BigInt.prototype.toString() Method
  • Last Updated : 02 Apr, 2020

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:




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:




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
  • Firefox
  • Opera
  • Safari
  • Edge
My Personal Notes arrow_drop_up
Recommended Articles
Page :