From 69ccc90854c164127a80a8c70c33b5d68f61a7e2 Mon Sep 17 00:00:00 2001 From: Dom Leonard <2seldom@gmail.com> Date: Thu, 20 Jul 2023 11:46:37 +0930 Subject: [PATCH 1/4] Update index.md --- .../en-us/web/javascript/reference/statements/var/index.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/files/en-us/web/javascript/reference/statements/var/index.md b/files/en-us/web/javascript/reference/statements/var/index.md index 2564e4cb8d6e811..0b9d215164e310e 100644 --- a/files/en-us/web/javascript/reference/statements/var/index.md +++ b/files/en-us/web/javascript/reference/statements/var/index.md @@ -40,7 +40,10 @@ The scope of a variable declared with `var` is one of the following curly-brace- - Function body - [Static initialization block](/en-US/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks) -Or the current module or script, if it's contained in neither of these. +Or if neither of these apply: + +- [Module scope](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) - the scope for code running in module mode. Or +- [Global scope] - the default scope for all code running in script mode. ```js function foo() { @@ -81,7 +84,7 @@ The list that follows the `var` keyword is called a _{{glossary("binding")}} lis ### Hoisting -`var` declarations, wherever they occur, are processed before any code is executed. Declaring a variable anywhere in the code is equivalent to declaring it at the top. This also means that a variable can appear to be used before it's declared. This behavior is called [_hoisting_](/en-US/docs/Glossary/Hoisting), as it appears that the variable declaration is moved to the top of the function or global code. +`var` declarations, wherever they occur, are processed during JavaScript compilation before any code is executed. Declaring a variable anywhere in the code is equivalent to declaring it at the top. This also means that a variable can appear to be used before it's declared. This behavior is called [_hoisting_](/en-US/docs/Glossary/Hoisting), as it appears that the variable declaration is moved to the top of the function or global code. ```js bla = 2; From 59780c59fba3181bba39bdda8918ba926163781d Mon Sep 17 00:00:00 2001 From: Dom Leonard <2seldom@gmail.com> Date: Thu, 20 Jul 2023 23:01:05 +0930 Subject: [PATCH 2/4] Update files/en-us/web/javascript/reference/statements/var/index.md Co-authored-by: Joshua Chen --- files/en-us/web/javascript/reference/statements/var/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/files/en-us/web/javascript/reference/statements/var/index.md b/files/en-us/web/javascript/reference/statements/var/index.md index 0b9d215164e310e..2ca74de796b7ce5 100644 --- a/files/en-us/web/javascript/reference/statements/var/index.md +++ b/files/en-us/web/javascript/reference/statements/var/index.md @@ -84,7 +84,9 @@ The list that follows the `var` keyword is called a _{{glossary("binding")}} lis ### Hoisting -`var` declarations, wherever they occur, are processed during JavaScript compilation before any code is executed. Declaring a variable anywhere in the code is equivalent to declaring it at the top. This also means that a variable can appear to be used before it's declared. This behavior is called [_hoisting_](/en-US/docs/Glossary/Hoisting), as it appears that the variable declaration is moved to the top of the function or global code. +`var` declarations, wherever they occur in a script, are processed before any code within the script is executed. Declaring a variable anywhere in the code is equivalent to declaring it at the top. This also means that a variable can appear to be used before it's declared. This behavior is called [_hoisting_](/en-US/docs/Glossary/Hoisting), as it appears that the variable declaration is moved to the top of the function, static initialization block, or script source in which it occurs. + +> **Note:** `var` declarations are only hoisted to the top of the current script. If you have two `