JavaScript Error Types Reference

Every built-in JS Error subtype with throw conditions and message patterns.

Reference for JavaScript built-in error types — TypeError, RangeError, ReferenceError, SyntaxError, URIError, EvalError, AggregateError — with what throws each, typical messages and how to catch them.

What is the difference between TypeError and ReferenceError?

A ReferenceError fires when you access a variable that does not exist in scope, such as using an undeclared name. A TypeError fires when a value exists but is the wrong type for the operation, such as calling a non-function or reading a property of null or undefined.

Know which error you caught

JavaScript has a small set of built-in Error subtypes, each thrown by specific operations. Recognising the subtype tells you the class of bug instantly. This reference lists every standard error type, what throws it, a typical message and how to catch it with instanceof.

How it works

Every built-in error inherits from Error and carries name, message and a stack. The engine throws the most specific subtype for the failure, which you can branch on:

try {
  null.foo;            // TypeError: Cannot read properties of null
} catch (e) {
  if (e instanceof TypeError) handleType(e);
  else if (e instanceof RangeError) handleRange(e);
  else throw e;        // re-throw anything you do not handle
}

Because all subtypes extend Error, e instanceof Error is always true — order your checks from most specific to least, and re-throw what you cannot handle.

Tips and notes

  • instanceof can fail across realms (iframes, worker boundaries) where each has its own Error constructor — check e.name as a fallback in that case.
  • SyntaxError from static source is uncatchable; only runtime-parsed code (JSON.parse, eval, new Function) throws a catchable one.
  • Use Error.cause (new Error(msg, { cause })) to chain a lower-level error.
  • Custom errors should extend Error, call super(message) and set this.name.
  • A “Maximum call stack size exceeded” message is a RangeError, usually from unbounded recursion.