https://bigfrontend.dev/quiz/arguments
What does the code snippet below output by console.log
?
function log(a, b, c, d) {
console.log(a, b, c, d);
arguments[0] = 'bfe';
arguments[3] = 'dev';
console.log(a, b, c, d);
}
log(1, 2, 3);
function log(a, b, c, d) {
console.log(a, b, c, d); // 1,2,3,undefined
arguments[0] = 'bfe';
arguments[3] = 'dev';
console.log(a, b, c, d); // "bfe",2,3,undefined
}
log(1, 2, 3);
Even though arguments[3] = 'dev'
does add a fourth item to the arguments
object, it doesn't reassign the new value to d
, because the function call log(1, 2, 3)
doesn't supply an argument for the parameter d
and therefore d
is not bound to the arguments
object, which means its value cannot be updated by modifying the arguments object.