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 trialtomd
16,701 PointsWhy 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
Treehouse TeacherHi 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!
Craig Williams
1,524 PointsReturning 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
Full Stack JavaScript Techdegree Student 11,638 PointsIn 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
Dskellth theFirst
Courses Plus Student 66 PointsDskellth theFirst
Courses Plus Student 66 Pointsis it wrong to return it?