"EvalError" in JavaScript — What It Means and How to Fix It

What the JavaScript error "EvalError" means and how to fix it.

Published October 29, 2026

EvalError is a legacy error type related to eval(). Modern JavaScript rarely throws it; problems with eval usually raise SyntaxError or ReferenceError instead.

What it means and why it happens

eval() runs a string as code, which is slow and dangerous. Avoid it entirely.

Read the full message: it names the file and line where the problem was detected, which is the best place to start.

What you see

run the code
EvalError

Practical examples

Code that triggers it

eval('2 +')   // SyntaxError today

The fix

JSON.parse(text)   // for data
new Function('a', 'b', 'return a + b')   // still risky; prefer real functions

Content-Security-Policy blocks eval

Content-Security-Policy: script-src 'self'   # no 'unsafe-eval'

Common mistakes

  • Using eval for JSON or math.
  • Allowing unsafe-eval in CSP.
  • Executing user input.

Key takeaways

  • EvalError: EvalError is a legacy error type related to eval().
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

Why avoid eval?

It executes arbitrary code and disables optimisations.

How do I find which line caused EvalError?

The error message and stack trace show the file and line; start there and work backwards.

More JavaScript articles