Assigning to globals in strict mode

David Herman dherman at
Tue Oct 19 18:21:49 PDT 2010

> "use strict";
> var declared = 0;
> undeclared = declared++;
> My understanding is that in ES5 strict mode, declared ends up 1, but in Harmony it ends up 0. In both cases, undeclared is left undefined. Is that correct? Or maybe by "early error" you mean it's a parse error and therefore in Harmony, declared will not be defined at all.

As Allen says, Harmony is not yet done. But if it truly is lexically scoped (which I hope to be the case) then this program will be rejected at compile time and not executed. Moreover, if part of being lexically scoped means not having the global object in the scope chain (which I hope to be the case), then whether or not a Harmony script *compiles* has no effect on the global object, nor do global variables in Harmony affect the global object.

As for what happens in ES5 strict, I haven't followed the details of this thread closely enough. Either the check happens before evaluating the RHS, in which case window.declared is 0, or it happens after evaluating the RHS, in which case window.declared is 1.


More information about the es5-discuss mailing list