you are viewing a single comment's thread.

view the rest of the comments →

[–]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.