Skip to content

Commit 9e0f603

Browse files
committed
Use "which" instead of "that".
Fix joined independent clauses missing a comma. Use colon. Use hyphens for adjective. Add comma. Use introductory sentence. Use "the" article. Clarify dependent clauses. Use commas for introductory clauses. Fix comma splice.
1 parent be1968c commit 9e0f603

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

doc/en/function/scopes.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ is in the language is *function scope*.
1616
> **not** as an object literal. This, in conjunction with
1717
> [automatic insertion of semicolons](#core.semicolon), can lead to subtle errors.
1818
19-
There are also no distinct namespaces in JavaScript, that means that everything
19+
There are also no distinct namespaces in JavaScript, which means that everything
2020
gets defined in one *globally shared* namespace.
2121

2222
Each time a variable is referenced, JavaScript will traverse upwards through all
@@ -32,10 +32,10 @@ still has not found the requested name, it will raise a `ReferenceError`.
3232
var foo = '42'
3333

3434
The above two scripts do **not** have the same effect. Script A defines a
35-
variable called `foo` in the *global* scope and script B defines a `foo` in the
35+
variable called `foo` in the *global* scope, and script B defines a `foo` in the
3636
*current* scope.
3737

38-
Again, that is **not** at all the *same effect*, not using `var` can have major
38+
Again, that is **not** at all the *same effect*: not using `var` can have major
3939
implications.
4040

4141
// global scope
@@ -49,8 +49,8 @@ implications.
4949

5050
Leaving out the `var` statement inside the function `test` will override the
5151
value of `foo`. While this might not seem like a big deal at first, having
52-
thousands of lines of JavaScript and not using `var` will introduce horrible and
53-
hard to track down bugs.
52+
thousands of lines of JavaScript and not using `var` will introduce horrible,
53+
hard-to-track-down bugs.
5454

5555
// global scope
5656
var items = [/* some list */];
@@ -116,7 +116,7 @@ JavaScript **hoists** declarations. This means that both `var` statements and
116116
}
117117

118118
The above code gets transformed before any execution is started. JavaScript moves
119-
the `var` statements as well as the `function` declarations to the top of the
119+
the `var` statements, as well as the `function` declarations to the top of the
120120
nearest surrounding scope.
121121

122122
// var statements got moved here
@@ -146,11 +146,11 @@ Missing block scoping will not only move `var` statements out of loops and
146146
their bodies, it will also make the results of certain `if` constructs
147147
non-intuitive.
148148

149-
In the original code the `if` statement seemed to modify the *global
150-
variable* `goo`, while actually it modifies the *local variable* - after hoisting
149+
In the original code, although the `if` statement seemed to modify the *global
150+
variable* `goo`, it actually modifies the *local variable* - after hoisting
151151
has been applied.
152152

153-
Without the knowledge about *hoisting*, below code might seem to raise a
153+
Without the knowledge about *hoisting*, the below code might seem to raise a
154154
`ReferenceError`.
155155

156156
// check whether SomeImportantThing has been initiliazed
@@ -173,18 +173,18 @@ moved to the top of the *global scope*.
173173
### Name Resolution Order
174174

175175
All scopes in JavaScript, including the *global scope*, have the special name
176-
[`this`](#function.this) defined in them, which refers to the *current object*.
176+
[`this`](#function.this), defined in them, which refers to the *current object*.
177177

178-
Function scopes also have the name [`arguments`](#function.arguments) defined in
179-
them which contains the arguments that were passed to a function.
178+
Function scopes also have the name [`arguments`](#function.arguments), defined in
179+
them, which contains the arguments that were passed to a function.
180180

181181
For example, when trying to access a variable named `foo` inside the scope of a
182182
function, JavaScript will lookup the name in the following order:
183183

184-
1. In case there is a `var foo` statement in the current scope use that.
185-
2. If one of the function parameters is named `foo` use that.
186-
3. If the function itself is called `foo` use that.
187-
4. Go to the next outer scope and start with **#1** again.
184+
1. In case there is a `var foo` statement in the current scope, use that.
185+
2. If one of the function parameters is named `foo`, use that.
186+
3. If the function itself is called `foo`, use that.
187+
4. Go to the next outer scope, and start with **#1** again.
188188

189189
> **Note:** Having a parameter called `arguments` will **prevent** the creation
190190
> of the default `arguments` object.
@@ -223,7 +223,7 @@ while different in syntax, do behave the exact same way.
223223
### In Conclusion
224224

225225
It is recommended to always use an *anonymous wrapper* for encapsulating code in
226-
its own namespace. This does not only protect code against name clashes, it
226+
its own namespace. This does not only protect code against name clashes, but it
227227
also allows for better modularization of programs.
228228

229229
Additionally, the use of global variables is considered **bad practice**. **Any**

0 commit comments

Comments
 (0)