Created
July 18, 2021 17:31
-
-
Save delowardev/baf96e4dc8ad55e49c3158bc541837d3 to your computer and use it in GitHub Desktop.
Scope in JavaScript
This file contains 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
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