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.

Ru Song
Front End Web Development Techdegree Graduate 13,845 PointsWhy I need to reference ul again?
the ul has already been referenced in the global scope, but why we need to do it again:
ul.addEventListener('click', (e) => {
if (e.target.tagName === 'BUTTON') {
const li = e.target.parentNode;
const ul = li.parentNode; <------- ??
ul.removeChild(li)
2 Answers

Steven Parker
221,451 PointsThis "ul" is being located by traversing from the element that triggered the event. So if the same event handler were to be used with multiple lists, it would always select the correct one.
This might not seem necessary if there is only one list on the page, but it demonstrates "good practice" programming that would be capable of performing properly with more complex pages.

Leanne He
Full Stack JavaScript Techdegree Student 6,779 PointsThanks, same here! I have another, related question: Does this mean that the declaration of the variable ul within the function here overrules the variable ul as defined in the global scope? Is this always the case?

Steven Parker
221,451 PointsYes, and this is known as "shadowing". The global variable continues to exist and remains unchanged, but it cannot be accessed from within the function because of the new one with the same name.
Ru Song
Front End Web Development Techdegree Graduate 13,845 PointsRu Song
Front End Web Development Techdegree Graduate 13,845 PointsThank you for the explanation. Steven Parker
Doron Geyer
Full Stack JavaScript Techdegree Student 13,884 PointsDoron Geyer
Full Stack JavaScript Techdegree Student 13,884 Pointsthanks, just had the very same question come to mind.