课程: Mastering Web Developer Interview Code

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

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

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

课程: 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…

内容