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