let and file scope

# Mark Volkmann (11 years ago)

Does a top-level let in a file (not inside any function) create a global variable just like var or does it create a variable that is scoped to the source file?

# Ryan Scheel (11 years ago)

It creates a variable scoped to the source file.

# Rick Waldron (11 years ago)
# Allen Wirfs-Brock (11 years ago)

a bit of additional clarification: It depends upon whether the file is a module or a script file. If it is a module, then let-like declarations have file scope. If it is a normal script, then let-like declarations are global scope (visible to multiple script files) but does not create a property on the global object.

# Rick Waldron (11 years ago)

I missed this when I searched my notes on github: rwaldron/tc39-notes/blob/master/es6/2013-11/nov-21.md#46-the-global-scope-contour (credit to Brian Terlson for alerting me)