Creation of the `arguments` object

Mathias Bynens mathias at qiwi.be
Wed Jul 4 07:03:54 PDT 2012


http://ecma-international.org/ecma-262/5.1/#sec-10.6 says:

> When control enters an execution context for function code, an arguments
> object is created unless (as specified in 10.5) the identifier arguments
> occurs as an Identifier in the function’s FormalParameterList or occurs as
> the Identifier of a VariableDeclaration or FunctionDeclaration contained in
> the function code.

Following that logic, I would expect the following code to return `"undefined"`:

    function fn() {
      var arguments;
      return typeof arguments;
    };
    fn(); // "object"

However, in all engines I tested this in, it returns `"object"` instead.

On the other hand, this:

    function fn() {
      var arguments = undefined;
      return typeof arguments;
    };
    fn(); // "undefined"

…does return `"undefined"`. And so does this, in all engines except Opera:

    function fn(arguments) {
      return typeof arguments;
    };
    fn(); // "object" in Opera, "undefined" everywhere else

Did I misunderstand the spec?


More information about the es-discuss mailing list