Favorites

JavaScript ReferenceError Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
ReferenceError
JavaScript Errors · ConstructorThis object is supported by all modern browsers.
Updated 28th November 2026

A ReferenceError is thrown when code uses a variable that doesn't exist, or a let or const variable before it has been declared.

Description

A ReferenceError is thrown when you refer to a variable that doesn't exist, usually because of a typo or a missing declaration ("x is not defined"). It is also thrown when a let, const or class binding is used before its declaration runs, in what is called the temporal dead zone.

To check whether a global variable exists without risking this error, use typeof name !== 'undefined', since typeof doesn't throw for undeclared names.

Typos in variable names are the most common cause, and editors with TypeScript or a linter flag them before the code runs. In non-strict scripts, assigning to an undeclared variable silently creates a global instead of throwing, which hides mistakes; strict mode, modules and classes throw a ReferenceError instead.

Creating

new ReferenceError(message)

Example

try {
  console.log(notDeclared);
} catch (err) {
  console.log(err.name, err.message);
}

console.log(typeof notDeclared);   // no error

try {
  value;
  let value = 1;
} catch (err) {
  console.log(err instanceof ReferenceError);
}

Browser Support

The following information will show you the current browser support for the ReferenceError object. Hover over a browser icon to see the version that first introduced support for this object.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee