javascript
JavaScript Native Error Types
The built-in error constructors defined by the ECMAScript specification. Every runtime (browsers, Node.js, Deno) throws these as the base error types; framework and library-specific errors (e.g. Node's ERR_* codes) usually subclass or wrap one of these.
8 codes
references tc39.es/ecma262/developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
· All codes 8 codes
- AggregateError AggregateError Wraps multiple errors into a single error object, with the individual errors available on its `.errors` property. Thrown by Promise.any() when every promise in the input rejects.
- Error Error The generic base error constructor. Most thrown errors are instances of a more specific subclass (TypeError, RangeError, etc.) or a custom class extending Error, but code may throw a plain Error directly for application-level failures.
- EvalError EvalError Historically thrown for misuse of the global eval() function. Modern JavaScript engines no longer throw this error for any built-in operation; it remains only for backward compatibility and can still be thrown explicitly by user code.
- RangeError RangeError Thrown when a numeric value falls outside the range allowed by a function, such as an invalid array length, an out-of-range radix passed to Number.prototype.toString(), or excessive recursion ("Maximum call stack size exceeded").
- ReferenceError ReferenceError Thrown when code references a variable or identifier that does not exist in the current scope, such as using a variable before it is declared in a block that uses let/const (the "temporal dead zone"), or a typo in an identifier name.
- SyntaxError SyntaxError Thrown when code being parsed does not conform to JavaScript's grammar, such as a mismatched bracket, invalid JSON passed to JSON.parse(), or an unexpected token. Unlike other native errors, a SyntaxError from a top-level script or module is raised at parse time, before any code runs.
- TypeError TypeError Thrown when a value is not of the expected type, such as calling a non-function, or accessing a property on undefined/null. The most common variant is "Cannot read properties of undefined (reading '...')", usually caused by an unexpected undefined/null in a chain of property accesses.
- URIError URIError Thrown when a global URI-handling function such as decodeURIComponent(), decodeURI(), encodeURI(), or encodeURIComponent() is passed a malformed argument, e.g. an incomplete percent-encoded escape sequence.