Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 554 Bytes

2015-04-27-hoisting-is-dangerous.md

File metadata and controls

29 lines (24 loc) · 554 Bytes
layout title
layouts/post.njk
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!"