Skip to content

Instantly share code, notes, and snippets.

@alexshelkov
Last active February 4, 2022 18:17
Show Gist options
  • Save alexshelkov/b7911079d13707e96a8dce58da265ee7 to your computer and use it in GitHub Desktop.
Save alexshelkov/b7911079d13707e96a8dce58da265ee7 to your computer and use it in GitHub Desktop.
{ // start of the block scope
// TODO: try uncomment
// console.log(a);
// hoisting works differently for blocks scope, and it will throw an error:
// 'ReferenceError: Cannot access a before initialization'
let a = 1; // 'a' defined and we can start to use it
//
console.log(a);
} // end of the block scope, here 'a' becomes not defined
// TODO: try uncomment
// TODO: try change let to var in code above
// console.log(a);
// 'a' is not defined here so we will see an error:
// 'ReferenceError: a is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment