Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript DOM Scripting By Example Improving the Application Code Refactor 1: Create List Items

Dinu Comendant
Dinu Comendant
5,858 Points

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
seal-mask
.a{fill-rule:evenodd;}techdegree
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

Dinu Comendant
Dinu Comendant
5,858 Points

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
seal-mask
.a{fill-rule:evenodd;}techdegree
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