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 trialThanitsak Leuangsupornpong
7,490 PointsWhy in the print function,don't have return.But in the build list function have the return.
I don't quit sure when to use return?
2 Answers
Ace Motanya
31,756 PointsWhen the function is generating some value and you want to pass it back to the caller is when you want to use return.
If you want to store the return value, then you have to assign it to a variable
var value = someFunction();
This stores the return value of someFunction in value.
If you call the function without assigning the return value, then the value is just silently dropped like so:
someFunction();
Marlinda Davis
7,423 PointsI am also learning but I think the print function did not need a return because the div id = 'output' did it instead on the HTML page. Look at output and DOM (.getElementByID) on Mozilla Developer Network. It got confusing when he changed it up a little bit but I think he said there are courses that go more in depth here on TreeHouse. Hope that helps.
Thanitsak Leuangsupornpong
7,490 PointsThank for your opinion.
Thanitsak Leuangsupornpong
7,490 PointsThanitsak Leuangsupornpong
7,490 PointsDid you mean that when we call the function name,it doesn't have the value inside,we need to use return to pass the value to the function name right?
Thanitsak Leuangsupornpong
7,490 PointsThanitsak Leuangsupornpong
7,490 PointsCan you explain what did this mean
var value = someFunction();
This stores the return value of someFunction in value.
If you call the function without assigning the return value, then the value is just silently dropped like so:
someFunction();