Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

another curiosity about variable hoisting #343

Open
lewisje opened this issue May 29, 2016 · 1 comment
Open

another curiosity about variable hoisting #343

lewisje opened this issue May 29, 2016 · 1 comment

Comments

@lewisje
Copy link

lewisje commented May 29, 2016

The statement var something = something; works even as the first statement in its scope, because it is equivalent to

var something;
something = something;

and it, as imagined, sets something to undefined, even if something was already defined in an outer scope.

To make a local reference to an object in an outer scope with the same name, it needs to be passed in as a function parameter, because otherwise, the inner name will shadow the outer name because of hoisting.

@Cryptoxygen
Copy link

Awesome post! Hoisting just make sense for for me now. :-)
Thanks for spreading the knowledge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants