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 trialJennie Kim
2,658 PointsWhy is listItem declared in createNewTaskElement and again in addTask? Could you use 2 different names instead?
listItem is first declared within the scope of createNewTaskElement, which returns the appended listItem variable.
Another var listItem is then declared within the scope of addTask, assigning it back to createNewTaskElement and passing in a string parameter ('some new task').
Is there a reason not to give a unique name to listItem within addTask? Or is the same name given intentionally?
1 Answer
Jennie Kim
2,658 PointsNow on the next video, and it appears that the var name "listItem" is just a standard var identifier name, similar to "x" or "i". They are only accessible within the scope of the function in which they are declared, and won't get mixed up with each other.
I think the name "listItem" just threw me off. It might help to just think of "listItem" the same way as you would "x" or "i".