Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptJavaScript BigInt toString() Method

JavaScript BigInt toString() Method

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 
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments