InterviewHubPRO
Section Overview
Q233

Question 233 of 521

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

45%
JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

What are the different error names from error object

There are 7 different types of error names returned from error object,

Error NameDescription
AggregateErrorAn error indicating that multiple errors occurred
EvalErrorAn error has occurred in the eval() function
RangeErrorAn error has occurred with a number "out of range"
ReferenceErrorAn error due to an illegal reference
SyntaxErrorAn error due to a syntax error
TypeErrorAn error due to a type error
URIErrorAn error due to encodeURI()

Practical Code Example

javascript
// Core Error Names in JavaScript:
try {
  // null.f();        // TypeError
  // undeclaredVar;   // ReferenceError
  // eval('foo bar'); // SyntaxError
  // decodeURI('%');  // URIError
  // new Array(-1);   // RangeError
} catch (err) {
  console.log(err.name);    // e.g., 'TypeError'
  console.log(err.message); // Explanatory message
}