Skip to main content
InterviewHubPRO
Section Overview
Q344

Question 344 of 536

Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

64%
JavaScript & V8 Internals (536 Qs)•Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

What is the purpose of EvalError object

senior LevelCode ExampleAsync & PromisesEvent LoopHTTP & REST APIs

The EvalError object indicates an error regarding the global eval() function. Even though this exception is not thrown by JavaScript anymore, the EvalError object remains for compatibility. The syntax of this expression would be as below,

javascript
  new EvalError([message[, fileName[, lineNumber]]])

You can throw EvalError with in try...catch block as below,

javascript
  try {
    throw new EvalError('Eval function error', 'someFile.js', 100);
  } catch (e) {
    console.log(e.message, e.name, e.fileName);              // "Eval function error", "EvalError", "someFile.js"