From the course: JavaScript: Classes

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Hoisting explained with classes

Hoisting explained with classes - JavaScript Tutorial

From the course: JavaScript: Classes

Hoisting explained with classes

- [Instructor] Hoisting is always a subject that is confusing for newcomers. So let's explore this a bit and how it relates to classes. So we're back in the app.js, and just to show you that a class has to be declared before it can be run. Let's go in, copy this code here or all of it actually from 13 to 16 like so. And I'm going to also comment this and add it to the top of the class. Now if I save this and I go back to my server we got an error. So basically we cannot use anything from the class until it actually is declared. So this code will work, this code won't work. So let me delete that. Bring that back on command this and save. And as you can see, everything is running as it should. But what about functions? What if I created a function here that say hi and that function will return? Console log. Hello? This function can be called anywhere. So if I save that and I go to the top here and I run this…

Contents