Skip to content

Instantly share code, notes, and snippets.

@bad6e
Created November 21, 2019 23:40
Show Gist options
  • Save bad6e/cc6e2417eeb5b2811ea384e77fd38833 to your computer and use it in GitHub Desktop.
Save bad6e/cc6e2417eeb5b2811ea384e77fd38833 to your computer and use it in GitHub Desktop.
function blockScope() {
if(true) {
// I am inside the block
var functionScopeVariable = 'functionScopeVariable'
const blockScopedVariable1 = 'blockScopedVariable1'
let blockScopedVariable2 = 'blockScopedVariable2'
}
console.log(functionScopeVariable)
console.log(blockScopedVariable1)
console.log(blockScopedVariable2)
}
blockScope()
// returns
// functionScopeVariable
// Uncaught ReferenceError: blockScopedVariable1 is not defined
// at blockScope (<anonymous>:8:15)
// at <anonymous>:1:1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment