-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
new-exampleA proposal of the new exampleA proposal of the new example
Description
When calling eval
indirectly, it uses the top scope. This means you can access the top scope variables even in a local scope where the same variable name is redefined. (Note that the variable is defined with let
, so it is not a property of the global object.)
let foo = 'outer';
(() => {
let foo = 'inner';
console.log(eval('foo')); // > "inner"
console.log(eval?.('foo')); // > "outer"
})();
This behavior is explained in the MDN documentation on eval.
TheKonka, Rudxain and tj-commitsRudxainRudxainTheKonka, xhyrom, MaxLiebsch and Rudxain
Metadata
Metadata
Assignees
Labels
new-exampleA proposal of the new exampleA proposal of the new example