Merge pull request #279 from usernamehw/patch-21

Update article.md
This commit is contained in:
Ilya Kantor 2017-11-01 08:59:12 +03:00 committed by GitHub
commit f91d41406e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,7 +52,7 @@ If we used `let test` on the 2nd line, then it wouldn't be visible to `alert`. B
The same thing for loops: `var` cannot be block- or loop-local:
```js
for(var i = 0; i < 10; i++) {
for (var i = 0; i < 10; i++) {
// ...
}
@ -61,7 +61,7 @@ alert(i); // 10, "i" is visible after loop, it's a global variable
*/!*
```
If a code block in inside a function, then `var` becomes a function-level variable:
If a code block is inside a function, then `var` becomes a function-level variable:
```js
function sayHi() {
@ -76,7 +76,7 @@ sayHi();
alert(phrase); // Error: phrase is not defined
```
As we can see, `var` pierces through `if`, `for` or other code blocks. That's because long time ago in JavaScript blocks had no Lexical Environments. And `var` is a reminiscence of that.
As we can see, `var` pierces through `if`, `for` or other code blocks. That's because a long time ago in JavaScript blocks had no Lexical Environments. And `var` is a reminiscence of that.
## "var" are processed at the function start
@ -184,4 +184,4 @@ There are two main differences of `var`:
There's one more minor difference related to the global object, we'll cover that in the next chapter.
These differences are actually a bad thing most of time. First, we can't create block-local variables. And hoisting just creates more space for errors. So, for new scripts `var` is used exceptionally rarely.
These differences are actually a bad thing most of the time. First, we can't create block-local variables. And hoisting just creates more space for errors. So, for new scripts `var` is used exceptionally rarely.