Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 596 Bytes

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

File metadata and controls

28 lines (24 loc) · 596 Bytes
layout title
post
Hoisting Can Be Dangerous

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

{% highlight js%} sayHi() function sayHi(){ console.log('oh hey') } {% endhighlight %}

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

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