Skip to content

JavaScript RangeError

  • by

In JavaScript, a RangeError can arise when a value exceeds the accepted range of values for a given operation. Whenever code tries to create or manipulate a value that falls outside of the acceptable range, this error is thrown.

JavaScript RangeError example

Simple example code

<!DOCTYPE html>
<html>
<body>
    <script>
        var n =  3.54
        console.log(n.toFixed(-100));
    </script>
</body>
</html>

Output:

JavaScript RangeError

The toFixed() method expects a non-negative argument indicating the number of digits to appear after the decimal point. In this case, the argument passed to toFixed() is -100, which is outside the valid range of arguments. As a result, the code will throw a RangeError with the message “toFixed() argument must be between 0 and 100″.

Do comment if you have any doubts on this Js error topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading