Error
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
Error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions. See below for standard built-in error types.
Description
Runtime errors result in new Error objects being created and thrown.
Error is a serializable object, so it can be cloned with structuredClone() or copied between Workers using postMessage().
Error types
Besides the generic Error constructor, there are other core error constructors in JavaScript. For client-side exceptions, see Exception handling statements.
EvalError-
Creates an instance representing an error that occurs regarding the global function
eval(). RangeError-
Creates an instance representing an error that occurs when a numeric variable or parameter is outside its valid range.
ReferenceError-
Creates an instance representing an error that occurs when de-referencing an invalid reference.
SyntaxError-
Creates an instance representing a syntax error.
TypeError-
Creates an instance representing an error that occurs when a variable or parameter is not of a valid type.