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 JavaScript and the DOM (Retiring) Traversing the DOM Getting All Children of a Node with children

tomd
tomd
16,701 Points

Why is there no return in the function?

I don't understand. We are sending in the li's to get their buttons, surely we want them to return with there new buttons. Or is there no need for them to return because we have already appended the buttons to the li's?

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Generally, we return when we need the result of something. Very often we use functions to do something and display the result right then and there. There is no need for getting a result here. We sent in the list item, created all the buttons and put them all on the document. There is nothing that needs to be returned in this case.

Hope this helps! :sparkles:

is it wrong to return it?

Craig Williams
Craig Williams
1,524 Points

Returning something from a function is only needed when you want to perform additional things after the function is run, so the purpose of running that particular function would be to get something to use later.

In this instance there is no need to return anything as the task to add the buttons to the li's is all carried out within the function. Returning a value from this function would do nothing as it isn't being stored anywhere, notice there is no variable defined for the function to be executed.

Aakash Srivastav
seal-mask
.a{fill-rule:evenodd;}techdegree
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,625 Points

In this case , you can see , within the attachListItemButtons , we are performing the whole operation ( i,e creating and appending) . DOM gets updated there . Then why we would need return statement.
return is needed only when you have to perform some opereation on the result obtained from the function , which is not the case here.
Thanks