Skip to content

Instantly share code, notes, and snippets.

@ernestlv
Last active June 7, 2023 18:51
Show Gist options
  • Save ernestlv/dcff29e584e7d45e88473ddbf61ef2f7 to your computer and use it in GitHub Desktop.
Save ernestlv/dcff29e584e7d45e88473ddbf61ef2f7 to your computer and use it in GitHub Desktop.
arguments and strict mode
/* 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