Skip to content

Instantly share code, notes, and snippets.

@simonespa
Created August 10, 2020 16:53
Show Gist options
  • Select an option

  • Save simonespa/61b4c2a53c0a02f551550d4507fc08f2 to your computer and use it in GitHub Desktop.

Select an option

Save simonespa/61b4c2a53c0a02f551550d4507fc08f2 to your computer and use it in GitHub Desktop.
Scope vs. Visibility in Javascript
/**
* 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