HTML CSS Bootstrap Javascript Icons Python
JavaScript Reference
Overview
JS Reference
JS Array Object JS Boolean Object JS Date Object JS Style Declaration Object JS Error Object JS Global Object JS Math Object JS Number Object JS String Object JS RegExp Object JS Statements
DOM Reference
DOM Attribute DOM Console DOM Document DOM Element DOM Events DOM Event Objects DOM History DOM HTMLCollection DOM Location DOM Navigator DOM Screen DOM Style DOM Window WEB Storage

JavaScript Error Reference

Error Object

The Error constructor creates an error object. Instances of Error objects are thrown when runtime errors occur.

The Error object provides error information when an error occurs.

Run code

You can learn more about Errors in our JavaScript Exception Tutorial.


Error Object Properties

The following table lists the properties of the Error object:

Property Description
name Sets or returns an error name
message Sets or returns an error message

Error Object Methods

The global Error object contains no methods of its own, however, it does inherit some methods from the prototype chain.

Error types

There are seven core error constructors in JavaScript:

Type Description
EvalError Creates an instance representing an error that occurs regarding the global function eval()
InternalError Creates an instance representing an error that occurs when an internal error in the JavaScript engine is thrown
RangeError Creates an instance representing an error that occurs when a numeric variable or parameter is outside of its valid range
ReferenceError Creates an instance representing an error that occurs when de-referencing an invalid reference
SyntaxError Creates an instance representing a syntax error that occurs while parsing code in eval()
TypeError Creates an instance representing an error that occurs when a variable or parameter is not of a valid type
URIError Creates an instance representing an error that occurs when encodeURI() or decodeURI() are passed invalid parameters

Non-Standard Error Object Properties

Microsoft and Mozilla defines some non-standard error object properties:

  • fileName (Mozilla)
  • lineNumber (Mozilla)
  • columnNumber (Mozilla)
  • stack (Mozilla)
  • description (Microsoft)
  • number (Microsoft)

Do not use these properties, they will not work in all browsers.