From the course: Mastering Web Developer Interview Code

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

What is variable hoisting and how do you guard against it?

What is variable hoisting and how do you guard against it?

From the course: Mastering Web Developer Interview Code

What is variable hoisting and how do you guard against it?

- [Instructor] JavaScript can be a tough language to learn, and often during interviews, you'll be presented with some code and asked to show what the result of that code will yield. So this week we're going to take a look at a classic issue that can trip people up during interviews, and that's hoisting. Now, with JavaScript variable and function declarations are processed before the code is executed, and this is what we call the hoisting, because in essence it moves the declarations to the top of the relevant scope. So you have to be careful if you start using the var keyword, and also pay attention to when you use function and function declarations. Now though declarations are hoisted, assignments are not, and that includes function expressions, which can create some other types of errors. We'll take a look at some examples in just a minute. Because of the way that JavaScript handles scope, hoisting can create other…

Contents