CKTIS / JavaScript
ReferenceError — invalid variable references
ReferenceError is a built-in JavaScript error type thrown, among other cases, when reading an unresolved name or a variable before initialization. Learn how a missing variable differs from undefined and why typeof does not bypass initialization rules.
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 ReferenceError(message)
ReferenceError(message)ReferenceError is a built-in ECMAScript error type that inherits from Error, not a Web API. The engine throws it, among other cases, when an identifier being read does not resolve to an accessible binding, such as after a typo or when using a name outside its scope. A declared, initialized variable whose value is undefined is not the same as a missing binding.
Reading a variable declared with let or const before its initialization also throws ReferenceError. This interval is called the temporal dead zone (TDZ). The typeof operator returns "undefined" for an unresolved name, but does not bypass the TDZ: typeof value before initialization of a local let value throws. By contrast, an ordinary read of a missing property on an ordinary object returns undefined, not ReferenceError.
new ReferenceError(message) creates an error object; calling ReferenceError(message) without new is also allowed. The message argument is optional. Creating the object does not throw it — that requires throw. Use try...catch to handle expected errors, but fix typos and incorrect initialization order at their source. The exact wording of engine-generated messages can differ between implementations.
Examples
(() => {
try {
console.log(typeof value);
let value = 42;
} catch (error) {
console.log(error instanceof ReferenceError);
console.log(error.name);
}
const custom = new ReferenceError("Missing binding");
console.log(custom.message);
})();Result
true ReferenceError Missing binding
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.