Created
August 10, 2020 16:53
-
-
Save simonespa/61b4c2a53c0a02f551550d4507fc08f2 to your computer and use it in GitHub Desktop.
Scope vs. Visibility in Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * The scope of the first "one" variable is the region of the function a, included function b. | |
| * Its visibility though doesn't coincide, because the second variable called "one" within the function "b" | |
| * hides it. This doesn't mean that the scope is reduced. | |
| */ | |
| function a() { | |
| const one = 1; | |
| function b() { | |
| const one = -1; | |
| const two = 2; | |
| console.log(one); | |
| console.log(two); | |
| } | |
| b(); | |
| } | |
| a(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment