Last active
June 7, 2023 18:51
-
-
Save ernestlv/dcff29e584e7d45e88473ddbf61ef2f7 to your computer and use it in GitHub Desktop.
arguments and 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(a) { | |
arguments[0] = 'a'; //local arguments synch up with argument variable | |
console.log(a, arguments[0], test.arguments[0]); | |
} | |
test(1,2); // prints a, a, 1 | |
/*strict mode */ | |
function test2(a) { | |
"use strict"; | |
arguments[0] = 'a'; | |
console.log(a, arguments[0], test2.arguments[1]); | |
} | |
test2(1,2) // throws error because <Function>.arguments is not allowed | |
/*strict mode */ | |
function test3(a) { | |
"use strict"; | |
arguments[0] = 'a'; //local arguments is not synch up with first argument variable | |
console.log(a, arguments[0], arguments[1]); | |
} | |
test3(1,2); // prints 1, a 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment