2

I just discovered that the arguments object actually changes if one of the parameters change.

For example:

function some(a, b, c ){
  console.log(arguments);


  args = [ a, b, c ];
  a = new Date();

  console.log(arguments);
  console.log(args);
}

some(1,2,3 );

You will see that while args stays the same (expected behaviour), arguments actually change.

Questions:

  • Is this something that is well documented? If so, where?

  • Is there anything else I need to be careful about the arguments object?

1

1 Answer 1

4

This is specified in the ECMA standard sec-10.6:

For non-strict mode functions [...] the number of formal parameters of the corresponding function object initially share their values with the corresponding argument bindings in the function’s execution context. This means that changing the property changes the corresponding value of the argument binding and vice-versa. This correspondence is broken if such a property is deleted and then redefined or if the property is changed into an accessor property. For strict mode functions, the values of the arguments object’s properties are simply a copy of the arguments passed to the function and there is no dynamic linkage between the property values and the formal parameter values.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow. What an odd behavior. Thanks for the reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.