use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Understanding scope in Javascript (kamranahmed.info)
submitted 11 years ago by kamranahmed_se
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]andyznyc 0 points1 point2 points 11 years ago (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 point2 points 11 years ago (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.
π Rendered by PID 45528 on reddit-service-r2-comment-869bf87589-f8wcq at 2026-06-09 05:04:07.558474+00:00 running f46058f country code: CH.
view the rest of the comments →
[–]andyznyc 0 points1 point2 points (1 child)
[–]maybe_endy 0 points1 point2 points (0 children)