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 DOM Scripting By Example Improving the Application Code Refactor 1: Create List Items

8:40 is soooo confusing

I've been looking at several answers in the community section but I still don't understand why label is out of scope of the checkbox. Would someone maybe be able to map it out of why label is out of scope?

Reggie Williams
Reggie Williams
Treehouse Teacher

Hey Dinu Comendant previously the label was being stored in the label variable, now it's being appended to the page without being stored in the variable as before. This leads Guil to return label so he has access to it.

1 Answer

I think I start to get it, but just to be sure: Basically, the function itself is in a way creating a variable, and the return statement works more or less as declaring it like 'const element = example' for others to see it?

Reggie Williams
Reggie Williams
Treehouse Teacher

You're on the right track! The element variable is defined earlier in a statement in the function body but the return statement gives other functions access to it

Thanks a lot, Reggie!