Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

ErrorEvent — error description and associated value

ErrorEvent is a Web API interface describing errors in scripts or files. Its message property provides a textual description, while error holds the associated JavaScript value—not necessarily an Error object.

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 ErrorEvent(type, { message, error });
event.message;
event.error;

ErrorEvent represents an event containing information about an error in a script or file. It inherits from Event and is also available in Web Workers. It is a Web API interface defined by the HTML standard, not an ECMAScript built-in object. Having Node 24 in a project does not establish browser support for this API.

ErrorEvent.message is a read-only property returning a human-readable error description as a string. ErrorEvent.error is also read-only, but returns the associated JavaScript value. This can be an Error or DOMException, but do not assume that type: check the value and its type before accessing error-specific properties.

new ErrorEvent(type, { message, error }) creates an event with a separately supplied description and error value. event.message need not equal event.error.message. The example deliberately supplies different strings, and the === comparison shows that error refers to the same object as cause. Merely constructing the event neither throws an exception nor dispatches the event to listeners.

Examples

(() => {
  const cause = new Error("Invalid input");
  const event = new ErrorEvent("error", {
    message: "Validation failed",
    error: cause,
  });

  console.log(event.message);
  console.log(event.error === cause);
  console.log(event.error.message);
})();

Result

Validation failed
true
Invalid input

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources