http://jsbin.com/ifabem/2/edit
"use strict";
window.x = "Hello World";
alert(x); // this does't throw an exception in strict mode
Why doesn’t accessing x directly in the last statement violate strict mode and throw an exception?
Is it the case that a violating is only writing a new value into the global object, but reading and even modifying an existing object allowed?
The phrase “gaining access to the global object” does not occur in the spec, so doesn’t have a clear definition; but looking through Appendix C of the spec (a non-normative listing of the effects of strict-mode), the only restriction that I think could be described that way is this one:
So you’re not allowed to add a property to the global object without using
varorwindow.or whatnot, but there’s nothing to stop you from getting a property of the global object — or even setting the value of an existing property.(By the way, the relevant bit of §8.7.2 is not terribly meaningful out-of-context, but for completeness’ sake, it’s this:
)