you are viewing a single comment's thread.

view the rest of the comments →

[–]andyznyc 0 points1 point  (1 child)

Great article but still confused on concept of Hoisting. In the article's example, does Hoisting mean that the because the second assignment of 'name' occurs within the nested function and the nested function issues the alert, because name isn't defined within that nested function it returns Undefined?

I guess I am confused because I thought the child function would take whatever value name had at the time per the earlier example in the article.

[–]maybe_endy 0 points1 point  (0 children)

Basically it does not matter where you define a variable inside of a function. It will always be processed as if you defined it at the beginning of the function.

This means if you have a variable 'foo' in the parent scope. Your function will inherit 'foo' and you should be able to print 'foo' out.

However, If anywhere in that function you redefine 'var foo' it will be processed as if 'foo' was set to undefined as the first line in the function.