function func1(str) {
eval(str);
newVar = 100;
function func2() {
console.log(bar);
console.log(newVar);
}
func2();
}
func1("bar = 42;");
I've read that the eval() keyword should be avoiding because it cheats the lexical scope (which results in code running slower). With the context of the above example (or any other examples anybody has) i'm trying to understand what kind of compiler optimizations this might end up breaking.
Looking at the line newVar = 100; this variable too will be created by the engine (on the global scope) during the execution phase. I don't think this amounts to 'cheating' the lexical scope. Then whats the issue with eval("bar = 42;") which essentially does something similar? Hope the question is clear.