JS Built-ins
RangeErrorintermediate

RangeError β€” catching from built-in

πŸ“– Usage Example
(1.5).toFixed(200)  // throws RangeError: toFixed() digits argument must be between 0 and 100

toFixed() throws a RangeError when the number of decimal places is out of range.

Catching RangeError

Creating an array with a negative length throws a RangeError.

Challenge: Catch the RangeError and verify it is an instance of RangeError.

πŸ’‘ Hints (1)
  • β€’ new Array(-1) throws a RangeError because -1 is not a valid array length.