There are a few things you can take away from this. If you understand hoisting, you should able to prevent hoisting related confusion for yourself or anyone else reading your code in the future. One way to do this is to write your code with hoisting in mind. Make sure to declare your variables and functions at the top of the scope. Since hoisting will essentially do this for you at run-time, you will avoid confusion if you write your code in the order that it will be processed. With this you will be able to plainly see if a variable used in a function hasn't yet been initialized or if the value changes before the function gets called. Next, know when to use function declarations as opposed to function expressions. In some cases, it doesn't really matter, but you should use them intentionally. Understand that function definitions are created before the code is ever executed and a function expression is created in place when the code is executed. It is generally recommended to use function declarations by default and use function expressions when there is a need. One case where you would want to use a function expression is when you are creating a function conditionally. Take a look at the following example:

if (true) { function foo() { return 'true'; } } else { function foo() { return 'false'; } } alert(foo());

var foo; if (true) { foo = function() { return 'true'; }; } else { foo = function() { return 'false'; }; } alert(foo());

Different browsers handle this case differently, but chances are your browser will alert 'false'! After learning about JavaScript hoisting, this probably makes sense. In this case, you should use function expressions:Declaringat the top of the scope will ensure that this variable remains local. Using function expressions will ensure that the variableis initialized when the code is executed rather than being hoisted before. If you've made it this far in the guide, I'm interested to know if you have any other concerns related to hoisting and if you have any other guidelines for when to use function declarations vs. expressions. If so, leave a comment below!