JavaScript RangeError Object
A RangeError is thrown when a number is outside the range of allowed values, such as an invalid array length or too many digits for toFixed().
Description
A RangeError is thrown when a value is not in the set or range of allowed values. Typical causes are creating an array with a negative length, passing more than 100 digits to toFixed(), an invalid radix for toString(), or a function that calls itself so many times that the call stack overflows ("Maximum call stack size exceeded").
Throw one yourself when an argument has the right type but an unacceptable value, for example a percentage above 100.
A "Maximum call stack size exceeded" error usually points to a recursive function without a working base case, or two functions that keep calling each other. Other sources include String.prototype.repeat() with a negative count, Array.prototype.with() with an index outside the array, an invalid date passed to toISOString(), and unsupported options in Intl formatters. Like all errors, it can be caught with try...catch.
Creating
new RangeError(message)Example
Browser Support
The following information will show you the current browser support for the RangeError object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





