Beginner Javascript WesBos - Hoisting

So I've started following Wes Bos' new Beginner Javascript course which so far is going really good. Starting off with the basics but mixing elements of other stuff too which is cool.

This episode I've watched is about hoisting and how it works when the browser runs, it pulls up all your functions / variables (declares them with no value) to the top of the page before anything else is run. Which enables calls throughout your script tags / sheets to still be able to run the function whether or not the calls are above or below the function.

example:

hey();
function hey() {console.log('hey there');}

The above code will work just fine because the function goes to the top when the browser is run.

Nice to know for when writing out your code though as best practice I'd believe to write out my functions / variables first, then the calls afterwards.

Well first post in a while however, think I'll be posting a bit more of my learning's on here going forward.

Catch ya later!!

Top