Skip to content

Instantly share code, notes, and snippets.

@ernestlv
Last active June 7, 2023 18:51
Show Gist options
  • Save ernestlv/ae05c9f92cde759fad95e2d671e8c89b to your computer and use it in GitHub Desktop.
Save ernestlv/ae05c9f92cde759fad95e2d671e8c89b to your computer and use it in GitHub Desktop.
eval behavior in strict mode
/* sloppy mode */
function test(arg) {
alert(eval("var arg = 1; arg")+" "+arg); //arg in eval changes arg in func context. if you declare arg suing let it will lock in eval context.
}
test(3); //prints 1 1
/* strict mode */
function test(arg) {
"use strict"
alert(eval("var arg = 1; arg")+" "+arg); //arg in eval does not change arg in func context
}
test(3); //prints 1 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment