Skip to content

Instantly share code, notes, and snippets.

@delowardev
Created July 18, 2021 17:31
Show Gist options
  • Save delowardev/baf96e4dc8ad55e49c3158bc541837d3 to your computer and use it in GitHub Desktop.
Save delowardev/baf96e4dc8ad55e49c3158bc541837d3 to your computer and use it in GitHub Desktop.
Scope in JavaScript
if (true) {
let x = 10;
var y = 10;
}
// `x` can't be accessed from outside of the if block
console.log(x) // return: Uncaught ReferenceError: x is not defined
// `y` can be accessed from outside of the if block
console.log(y) // return 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment