Assigning to globals in strict mode

Brendan Eich brendan at
Mon Oct 18 10:41:19 PDT 2010

On Oct 18, 2010, at 12:57 AM, Dmitry A. Soshnikov wrote:

> On 18.10.2010 1:56, Oliver Hunt wrote:
>> I'm just in the process of making jsc produce the correct error in strict mode when assigning to an undefined priority, and I just want to verify my understanding of the spec (which is somewhat confused by multiple people stating that in strict mode the assignment operator can never create a new global property).
>> Per section 11.13.1 an implementation should throw a syntax error if LeftHandSideExpression evaluates to an unresolvable reference, which means
>> "use strict"; undeclared = (this.undeclared = 5);
>> Should throw as |undeclared| will not exist when LeftHandSideExpression is evaluated.
> As far as I can see, yeah, it's a ReferenceError. However, it will be more logical not to have it (because of grouping operator which logically assumes precedence). The situation can be corrected if to exchange first and the second steps of the 11.13.1.

Those steps are intentionally in that order, so that mutations to the scope chain from evaluating the right-hand side of assignment do not alter the meaning of the left-hand side.

This goes back to ES1 and it's not going to change. It IMO is the right semantics, and a compatibility subtlety no one has good cause to take risks messing with.


More information about the es5-discuss mailing list