Home >Web Front-end >JS Tutorial >Do `let` Statements Create Global Object Properties in JavaScript?

Do `let` Statements Create Global Object Properties in JavaScript?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-26 11:52:09696browse

Do `let` Statements Create Global Object Properties in JavaScript?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn