0

In this blog post, it says that the argument object is created and assigned its value during creation of execution context, before any code is executed. However, in the book, YDKJS by Kyle Simpson, there is an example that looks like this,

function foo(a) {
  console.log( a ); // 2
}

foo( 2 );

and he says that the assignment of value '2' to the argument 'a' happens after the creation of execution context and during the code execution.
I've been trying to find a scenario where both would make sense but they seem like total opposite claims. When is the argument object created exactly? Thank you in advance!

2 Answers2

0

In the case of the blog, it is reffering to the arguments object (mdn link) , not the local variables, of which a is one.

  • Thanks for the reply! I thought arguments are like local variables. and in the link you gave me, it says "The arguments object is a local variable available within all functions." So when does the assignment of 2 into variable a happens? during the creation of execution context of after? – oneandwholly Apr 26 '17 at 11:34
  • @oneandwholly it depends what you mean by 'arguments'. note that "The arguments object is an Array-like object **corresponding** to the arguments passed to a function." –  Apr 26 '17 at 11:37
0

First the arguments list object is created on the caller side.

Then it's passed into the EvaluateDirectCall (or any other internal method that ends up calling a function) and then the execution context is created.

And after that when code evaluates - the references to the variables are obtained from the execution context.

All from above in details: FunctionDeclarationInstantiation

zerkms
  • 249,484
  • 69
  • 436
  • 539
  • Thanks! so is the blog post wrong when it says "Create the arguments object, check the context for parameters, initialize the name and value and create a reference copy."? – oneandwholly Apr 26 '17 at 11:42
  • I think it's the same as what I explained – zerkms Apr 26 '17 at 11:51
  • I think I was confusing about the argument object and the variables that are in the parameter. thanks for clarifying. it really helped. – oneandwholly Apr 26 '17 at 11:58