Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavascriptJavaScript RangeError – Radix must be an integer

JavaScript RangeError – Radix must be an integer

This JavaScript exception radix must be an integer at least 2 and no greater than 36 occurs if the radix parameter of the Number.prototype.toString() or the BigInt.prototype.toString() method is passed and is not in range between 2 and 36.

Output message:

RangeError: invalid argument (Edge)
RangeError: radix must be an integer at least 2
            and no greater than 36 (Firefox)
RangeError: toString() radix argument must be 
            between 2 and 36 (Chrome)

Error Type:

RangeError

Cause of the error: When the optional radix parameter of the Number.prototype.toString() or the BigInt.prototype.toString() method is specified and not between 2 and 36, A radix that is greater than 10 starts using alphabet characters as digits which can not be larger than 36(Because alphabet has only 26 letters).

Example 1: In this example, the parameter passed is 2, So the error has not occurred.

HTML




<body style="text-align: center;">
    <h1 style="color: green;">
        neveropen
    </h1>
  
    <p>
        JavaScript RangeError
        Radix must be an integer
    </p>
  
    <button onclick="Geeks();">
        click here
    </button>
    <p id="GFG_DOWN"></p>
  
    <script>
        var el_down = document.getElementById("GFG_DOWN");
        function Geeks() {
            try {
                (42).toString(2);
                el_down.innerHTML = 
                  "'Radix must be an" + 
                  " integer' error has not occurred";
            } catch (e) {
                el_down.innerHTML = 
                  "'Radix must be an" + 
                  " integer' error has occurred";
            }
        }
    </script>
</body>


Output:

JavaScript RangeError - Radix must be an integer

Example 2:  In this example, the parameter passed is 0, So the error has occurred.

HTML




<body style="text-align: center;">
    <h1 style="color: green;">
        neveropen
    </h1>
  
    <p>
        JavaScript RangeError
        Radix must be an integer
    </p>
  
    <button onclick="Geeks();">
        click here
    </button>
  
    <p id="GFG_DOWN"></p>
  
    <script>
        var el_down = document.getElementById("GFG_DOWN");
        function Geeks() {
            try {
                (42).toString(0);
                el_down.innerHTML = 
                  "'Radix must be an" + 
                  " integer' error has not occurred";
            } catch (e) {
                el_down.innerHTML = 
                  "'Radix must be an" +
                  " integer' error has occurred";
            }
        }
    </script>
</body>


Output:

JavaScript RangeError - Radix must be an integer

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!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments