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

JavaScript

Can anyone explain how this javascript works?

Hello guys,

I am reviewing the video titled 'Predicting closures output #4, https://www.youtube.com/watch?v=OtYyX97Nf-Q , from udacity js course and I have trouble grasping how after running the second newSaga() function, the following call to sagas[0] retains the var foil - 'Rat'. I know this is jumping right in the middle of things, the actualy course is located https://www.udacity.com , titled: 'Object-Oriented JavaScript'

I would think that running the newSaga() function a second time would in fact return a different foil value, similar to how calling sags[1] after it returns a different deed value. Can anyone explain exactly what's going on here, thanks!