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 trialtommy huynh
Full Stack JavaScript Techdegree Student 3,723 PointsCan someone explain to me what "return" does in simple English please?
I do not get the concept of "return" so if anyone can explain it in a simple and easy to understand way it will be greatly appreciated! =D
3 Answers
stjarnan
Front End Web Development Techdegree Graduate 56,488 PointsHi Tommy!
Imagine you have a friend, you and your friend is sitting in your couch watching a great movie when you suddenly get hungry. You ask your friend if he or she can make you a sandwich, and he goes to the kitchen to make you that sandwich. In the kitchen he puts butter, some vegetables etc on the sandwich. This could be seen as the function, you sending your friend away to do some stuff for you.
When he's done he could come back without the sandwich, he did not return anything. The function did not have a return statement.
If the function had a return statement, your friend would have brought you the sandwich he created for you with him.
Basically, if you have a return statement, you could save what the function returns somewhere else, like in a variable.
I hope that helps
Jonas
tommy huynh
Full Stack JavaScript Techdegree Student 3,723 PointsAhh I think I get it. So what it does is it actually saves what the function or method is doing? I'm pretty new to this so I assumed that everything would be saved automatically.
stjarnan
Front End Web Development Techdegree Graduate 56,488 PointsBasically yes :)
If you for example:
var variableName = run your function with a return statement here
Whatever the function returns can be saved in your variable.
It can feel tricky at first, I remember feeling confused regarding this myself :)