Skip to content

Instantly share code, notes, and snippets.

@pszponder
Created June 20, 2021 03:24
Show Gist options
  • Save pszponder/a66da32277ffe76d9156d59db9e62f4b to your computer and use it in GitHub Desktop.
Save pszponder/a66da32277ffe76d9156d59db9e62f4b to your computer and use it in GitHub Desktop.
function myFunc() {
// Declare a variable inside myFunc's funciton scope
var x = 1;
console.log(x);
if (true) {
var y = 2;
console.log(y);
}
console.log(y);
}
// Call the function
myFunc();
// Attempt to access x outside of the function scope is not possible
console.log(x); // Uncaught ReferenceError: x is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment