created by Brian LeRoux & Andrew Lunny. sparodically uncurated by David Trejo.

2012 04 18 changing variables changes arguments

It turns out that changing the value of an argument variable will change its value in the arguments "array":

    > function hello(what) {
    .     what = "world";
    .     return "Hello, " + arguments[0] + "!";
    . }
    > hello("shazow")
    "Hello, world!"

This is documented behaviour (see NOTE 1 in §10.6 Arguments Object of ECMA-262).

I suspect, without evidence, that this allows named argument value lookups to be transformed at compile time into a lookup into the arguments array (so, for example, the what = "world"; would be transformed into arguments[0] = "world"; much like Python's fast locals).

@wolever

Fork me on GitHub