~/ Hoisting Can Be Dangerous

Hoisting is often convenient in JavaScript. It allows us to call functions before they’re defined:

sayHi()
function sayHi(){
console.log('oh hey')
}

If you define a function inside of a conditional, you run the risk of having a function being overwritten via hoisting:

if(true){
function truthy(){
document.write("true is true!")
}
} else{
function truthy(){
document.write("true is false!")
}
}
truthy(); // will always log "true is false!"

~/ Posted by Jesse Shawl on 2015-04-27