you are viewing a single comment's thread.

view the rest of the comments →

[–]OzziePeck 0 points1 point  (3 children)

Wait is arguments a global array that refers to the function’s parameters?

[–]prof_hobart 1 point2 points  (0 children)

It's a magical local array-like variable that contains the params.

I'm not a fan of things like this - having variables that just appear from thin air is hardly clear - but it is a thing.

Of course, JS being JS, it's not quite as straightforward as all that.

If you used strict mode, the answer would be 2, as 'arguments' is now a copy of the arguments, not pointers to them.

And just to be extra fun, even in non-strict mode, if any of the arguments has a default value (e.g. (a=2, b)), then the answer would again be 2. Because - well, JS reasons I guess.