Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeaudru authored Sep 26, 2017
1 parent e963ba4 commit 51004aa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function myFunction() {
var myVar = "Nick";
console.log(myVar); // "Nick" - myVar is accessible inside the function
}
console.log(myVar); // Undefined, myVar is not accessible outside the function.
console.log(myVar); // Throws a ReferenceError, myVar is not accessible outside the function.
```

Still focusing on the variable scope, here is a more subtle example:
Expand All @@ -180,7 +180,7 @@ function myFunction() {
}
console.log(myVar); // "John" - see how the instructions in the if block affected this value
}
console.log(myVar); // Undefined, myVar is not accessible outside the function.
console.log(myVar); // Throws a ReferenceError, myVar is not accessible outside the function.
```

Besides, *var* declared variables are moved to the top of the scope at execution. This is what we call [var hoisting](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var#var_hoisting).
Expand Down Expand Up @@ -222,7 +222,7 @@ function myFunction() {
}
console.log(myVar); // "Nick", see how the instructions in the if block DID NOT affect this value
}
console.log(myVar); // Undefined, myVar is not accessible outside the function.
console.log(myVar); // Throws a ReferenceError, myVar is not accessible outside the function.
```

<a name="tdz_sample"></a> Now, what it means for *let* (and *const*) variables for not being accessible before being assigned:
Expand Down

0 comments on commit 51004aa

Please sign in to comment.