JavaScript EvalError Object
EvalError is a legacy error type that was once thrown for misuse of eval(). Modern JavaScript never throws it, but it remains for compatibility.
Description
The EvalError type was used in early versions of JavaScript for errors in the global eval() function. Current engines never throw it; problems with code passed to eval() produce a SyntaxError or other ordinary errors instead. It still exists so old code that checks for it keeps working.
You can still create an EvalError with new EvalError(message) and throw it yourself, and it inherits the usual name, message and cause properties from Error. There's little reason to, since its name suggests a connection with eval() that no longer exists.
The eval() function itself is best avoided: it runs any string as code, which is slow, makes code hard to follow, and opens the door to security problems if any of the string comes from users. Content Security Policies usually block it. Alternatives such as JSON.parse() for data, or property access with brackets for dynamic names, cover nearly every use.
Creating
new EvalError(message)Example
Browser Support
The following information will show you the current browser support for the EvalError object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





