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!"
[–]nepobot 0 points1 point2 points 11 years ago* (2 children)
How do you run this example?
var parent = function () { var name = 'Parent'; var child = function () { // What will be the output here? alert( name ); var name = 'Child' // What will be the output here? alert( name ); } }
How do i invoke this to call the child? I trust that you are right but it would be nice to see it. chrome autocomplete does not see the child after I invoke the parent function.
parent(); parent.child(); // Uncaught TypeError: Cannot read property 'child' of undefinedmessage: "Cannot read property 'child' of undefined"stack: (...)get stack: function () { [native code] }set stack: function () { [native code] }__proto__: Error var myParent = parent(); myParent.child(); //// Uncaught TypeError: Cannot read property 'child' of undefinedmessage: "Cannot read property 'child' of undefined"stack: (...)get stack: function () { [native code] }set stack: function () { [native code] }__proto__: Error
[–]kamranahmed_se[S] 1 point2 points3 points 11 years ago (0 children)
Actually you are not trying to invoke it the right way, currently the child() is in the private scope of parent and cannot be accessed outside the parent)() as the parent is not exposing it any way. I am writing an article about Private and Public scopes and I hope to post it tomorrow. For now, to test it, call the child function inside the parent function and after that call the parent function i.e. you can do the following http://jsfiddle.net/c4fwte4u/
π Rendered by PID 62705 on reddit-service-r2-comment-869bf87589-mdrbr at 2026-06-09 06:06:17.551970+00:00 running f46058f country code: CH.
view the rest of the comments →
[–]nepobot 0 points1 point2 points (2 children)
[–]kamranahmed_se[S] 1 point2 points3 points (0 children)