Skip to content

Instantly share code, notes, and snippets.

@thurt
Last active February 11, 2016 22:23
Show Gist options
  • Save thurt/fd8618e54bd197aa4372 to your computer and use it in GitHub Desktop.
Save thurt/fd8618e54bd197aa4372 to your computer and use it in GitHub Desktop.
Hoist Tests comparing var let and const
/*
var is function scoped & hoisted
let is block scoped & not hoisted
const is block scoped & not hoisted
*/
(() => {
'use strict'
const tests = [
() => {
console.info(a) // undefined
var a = 1
},
() => {
console.info(a) // throws error
let a = 1
},
() => {
console.info(a) // throws error
const a = 1
}
]
for (let test of tests) {
try { test() }
catch(e) { console.error(e) }
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment