Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Mark Warren
19,252 PointsDo you have to return the inside function in order for its value to appear outside the outer function?
function dogHouse() { var dogs = 8; function showDogs() { console.log(dogs); } return showDogs; // returned here }
var getDogs = dogHouse();
getDogs();
2 Answers
Dmitry Polyakov
4,989 Pointsyou are right. Inside function must be returned
Steven Parker
243,266 PointsI'm not sure what you mean by the "value to appear outside the outer function", but if by "inner function" you are referring to "showDogs", then that function is returned by "dogHouse" (the "outer function"?) so that when it is assigned to "getDogs" it can then be invoked using that name.
If the function "showDogs" had not been returned by "dogHouse", it would not be possible to access it later.