Skip to content

Latest commit

 

History

History
49 lines (31 loc) · 1.03 KB

12.arguments.md

File metadata and controls

49 lines (31 loc) · 1.03 KB

12. arguments

Problem

https://bigfrontend.dev/quiz/arguments

Problem Description

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);

Answer

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);

Explanation

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.

Reference

The JavaScript arguments object…and beyond