Skip to content

Instantly share code, notes, and snippets.

@cesarkohl
Created January 13, 2020 14:57
Show Gist options
  • Select an option

  • Save cesarkohl/db27f0672e629a382f701d14f9dee723 to your computer and use it in GitHub Desktop.

Select an option

Save cesarkohl/db27f0672e629a382f701d14f9dee723 to your computer and use it in GitHub Desktop.
let value = 0;
if (true) {
 // new scope, TDZ of 'value' begins
// When trying to access the variable, we take ReferenceError,
// because right now it's a variable
 // not initialized
 console.log (value); // ReferenceError
let value; // TDZ ends and 'value' is set to 'undefined'
 console.log (value); // undefined
value = 1;
 console.log (value); // 1
}
console.log (value); // 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment