CKTIS / JavaScript
RangeError — a value outside the allowed range
RangeError is a built-in ECMAScript error type indicating a value outside an allowed set or range. Use it to signal invalid arguments and handle such exceptions with try...catch.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
new RangeError(message)
RangeError(message)
throw new RangeError(message)RangeError is a built-in ECMAScript error type whose instances inherit from Error. It indicates a value outside an allowed set or range; this need not mean exceeding a numeric boundary. It is not a Web API interface.
new RangeError(message) creates an error object with an optional message. Calling RangeError(message) without new also creates a new object. Creating the error alone does not interrupt execution: use throw new RangeError(message) to throw an exception.
Some operations throw this error automatically. For example, new Array(-1) rejects a negative length. With a single Number argument, the Array constructor requires an integer length from 0 through 2 ** 32 - 1, inclusive. Reading an element beyond the end of an ordinary array does not itself throw RangeError.
Handle the expected exception in try...catch and rethrow unrelated errors. In the example, instanceof RangeError checks the type within the same realm; objects from another realm, such as a frame, may fail this test. Do not compare engine-generated error messages: their wording is not a portable contract.
Examples
try {
new Array(-1);
} catch (error) {
if (!(error instanceof RangeError)) throw error;
console.log(error.name);
console.log(error instanceof Error);
}Result
RangeError true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.