Last active
June 7, 2023 18:51
-
-
Save ernestlv/ae05c9f92cde759fad95e2d671e8c89b to your computer and use it in GitHub Desktop.
eval behavior in strict mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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