Created
July 18, 2017 20:14
-
-
Save lorepirri/8a80b02fd726f7b1ed782a862fde2a1b to your computer and use it in GitHub Desktop.
In Javascript scopes are defined at function level, if declared with var, on the other side es6 let/const define scope at a block level (e.g. in an if-block, or for loop)
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
console.clear(); | |
if (true) { | |
let insideJoke = 174; // let used -> block's scope | |
const anotherInsideJoke = 100; // const used -> block's scope | |
var thisIsACommonJoke = 42 // var used -> scope to outer scope (global) | |
} | |
console.log('thisIsACommonJoke', thisIsACommonJoke); // ok, global scope | |
console.log('insideJoke', insideJoke); // error: out of scope |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment