Update article.md

This commit is contained in:
Alexander 2017-10-27 00:40:14 +03:00 committed by GitHub
parent ccc0e9327f
commit dd6141fa9e

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: The same thing for loops: `var` cannot be block- or loop-local:
```js ```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 ```js
function sayHi() { function sayHi() {
@ -76,7 +76,7 @@ sayHi();
alert(phrase); // Error: phrase is not defined 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 ## "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. 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.