Global Object Property Creation in JavaScript
In JavaScript, the question arises: do let statements contribute to the creation of properties on the global object?
Unlike var declarations, which create global object properties, let declarations in ES6 have lexical scoping and block visibility. However, the question remains whether they impact the global object.
According to the ECMAScript specification, the answer is no. The global environment record comprises two components: an object environment record and a declarative environment record. Built-in globals, FunctionDeclarations, GeneratorDeclarations, and VariableStatements create bindings stored in the object environment record, which is linked to the global object.
However, all other declarations, including let, are contained in the declarative environment record. This record employs an internal data structure for binding storage, making it inaccessible to the global object.
Therefore, let statements do not create properties on the global object.
The above is the detailed content of Do `let` Statements Create Global Object Properties in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!