Junior From PDF JavaScript JavaScript

What is the difference between eval() and Function() constructor?

Both execute dynamic code, but:

  • eval() executes in the current scope (less safe).
  • Function() executes in a new scope (safer).

Example:

eval("var a = 5");
const b = new Function("return 5;");

⚠ Both are discouraged due to security and performance issues.

Bootstrap Interview Questions

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details