Skip to content

Commit 66149c2

Browse files
Port global var description to let (#30388)
* Port global var description to let * Update files/en-us/web/javascript/reference/statements/let/index.md Co-authored-by: Joshua Chen <[email protected]> --------- Co-authored-by: Hamish Willee <[email protected]>
1 parent 2b63de6 commit 66149c2

File tree

1 file changed

+6
-1
lines changed
  • files/en-us/web/javascript/reference/statements/let

1 file changed

+6
-1
lines changed

files/en-us/web/javascript/reference/statements/let/index.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ The scope of a variable declared with `let` is one of the following curly-brace-
3939
- Function body
4040
- [Static initialization block](/en-US/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks)
4141

42-
Or the current module or script, if it's contained in none of these.
42+
Or if none of the above applies:
43+
44+
- The current [module](/en-US/docs/Web/JavaScript/Guide/Modules), for code running in module mode
45+
- The global scope, for code running in script mode.
4346

4447
Compared with {{jsxref("Statements/var", "var")}}, `let` declarations have the following differences:
4548

@@ -104,6 +107,8 @@ This differs from using `typeof` for undeclared variables, and variables that ho
104107
console.log(typeof undeclaredVariable); // "undefined"
105108
```
106109

110+
> **Note:** `let` and `const` declarations are only processed when the current script gets processed. If you have two `<script>` elements running in script mode within one HTML, the first script is not subject to the TDZ restrictions for top-level `let` or `const` variables declared in the second script, although if you declare a `let` or `const` variable in the first script, declaring it again in the second script will cause a [redeclaration error](#redeclarations).
111+
107112
### Redeclarations
108113

109114
`let` declarations cannot be in the same scope as any other declaration, including `let`, {{jsxref("Statements/const", "const")}}, {{jsxref("Statements/class", "class")}}, {{jsxref("Statements/function", "function")}}, {{jsxref("Statements/var", "var")}}, and {{jsxref("Statements/import", "import")}} declaration.

0 commit comments

Comments
 (0)