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 trialM Khan
7,024 PointsWhy do we need to put outer function in a variable, why we can't just call the dogHouse function directly ?
var birds = 3;
function dogHouse(){
var dogs = 8;
function showDogs(){
echo(dogs);
}
return showDogs;
}
var getDogs = dogHouse();
getDogs();
1 Answer
Steven Parker
229,644 PointsThe "dogHouse" function returns another function, and the code is calling that other function.
But you could do it like this: "dogHouse()();
" — but that looks really strange!
M Khan
7,024 PointsM Khan
7,024 PointsClear. Grazie signore