@@ -73,7 +73,7 @@ unless the *desired effect* is to affect the outer scope.
73
73
### Local Variables
74
74
75
75
The only source for local variables in JavaScript are
76
- [ function] ( #function.general ) parameters and variables that were declared via the
76
+ [ function] ( #function.general ) parameters and variables declared via the
77
77
` var ` statement.
78
78
79
79
// global scope
@@ -115,8 +115,8 @@ JavaScript **hoists** declarations. This means that both `var` statements and
115
115
}
116
116
}
117
117
118
- 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
118
+ The above code gets transformed before execution starts . JavaScript moves
119
+ the ` var ` statements, as well as ` function ` declarations, to the top of the
120
120
nearest surrounding scope.
121
121
122
122
// var statements got moved here
@@ -150,15 +150,15 @@ In the original code, although the `if` statement seemed to modify the *global
150
150
variable* ` goo ` , it actually modifies the * local variable* - after hoisting
151
151
has been applied.
152
152
153
- Without the knowledge about * hoisting* , the below code might seem to raise a
153
+ Without knowledge of * hoisting* , one might suspect the code below would raise a
154
154
` ReferenceError ` .
155
155
156
156
// check whether SomeImportantThing has been initialized
157
157
if (!SomeImportantThing) {
158
158
var SomeImportantThing = {};
159
159
}
160
160
161
- But of course, the above works due to the fact that the ` var ` statement is being
161
+ But of course, this works due to the fact that the ` var ` statement is being
162
162
moved to the top of the * global scope* .
163
163
164
164
var SomeImportantThing;
@@ -176,10 +176,10 @@ All scopes in JavaScript, including the *global scope*, have the special name
176
176
[ ` this ` ] ( #function.this ) , defined in them, which refers to the * current object* .
177
177
178
178
Function scopes also have the name [ ` arguments ` ] ( #function.arguments ) , defined in
179
- them, which contains the arguments that were passed to a function.
179
+ them, which contains the arguments that were passed to the function.
180
180
181
181
For example, when trying to access a variable named ` foo ` inside the scope of a
182
- function, JavaScript will lookup the name in the following order:
182
+ function, JavaScript will look up the name in the following order:
183
183
184
184
1 . In case there is a ` var foo ` statement in the current scope, use that.
185
185
2 . If one of the function parameters is named ` foo ` , use that.
@@ -191,9 +191,9 @@ function, JavaScript will lookup the name in the following order:
191
191
192
192
### Namespaces
193
193
194
- A common problem of having only one global namespace is the likeliness of running
195
- into problems where variable names clash. In JavaScript, this problem can
196
- easily be avoided with the help of * anonymous wrappers* .
194
+ A common problem associated with having only one global namespace is the
195
+ likelihood of running into problems where variable names clash. In JavaScript,
196
+ this problem can easily be avoided with the help of * anonymous wrappers* .
197
197
198
198
(function() {
199
199
// a self contained "namespace"
@@ -208,13 +208,13 @@ easily be avoided with the help of *anonymous wrappers*.
208
208
Unnamed functions are considered [ expressions] ( #function.general ) ; so in order to
209
209
being callable, they must first be evaluated.
210
210
211
- ( // evaluate the function inside the paranthesis
211
+ ( // evaluate the function inside the parentheses
212
212
function() {}
213
213
) // and return the function object
214
214
() // call the result of the evaluation
215
215
216
- There are other ways for evaluating and directly calling the function expression; which,
217
- while different in syntax, do behave the exact same way.
216
+ There are other ways to evaluate and directly call the function expression
217
+ which, while different in syntax, behave the same way.
218
218
219
219
// A few other styles for directly invoking the
220
220
!function(){}()
@@ -224,7 +224,7 @@ while different in syntax, do behave the exact same way.
224
224
225
225
### In Conclusion
226
226
227
- It is recommended to always use an * anonymous wrapper* for encapsulating code in
227
+ It is recommended to always use an * anonymous wrapper* to encapsulate code in
228
228
its own namespace. This does not only protect code against name clashes, but it
229
229
also allows for better modularization of programs.
230
230
0 commit comments