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 trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Getting Information From a Function

Leo Penaloza
Leo Penaloza
8,426 Points

Using return values

What's the difference between using the Return value and just letting the code finish?

2 Answers

Steven Parker
Steven Parker
231,269 Points

If you use a plain "return;", there's no difference from just hitting the end of the function.

But if you use it to return a value (like "return someValue;") it sends that value back to the point of the program that called the function, where just hitting the end does not.

Leo Penaloza
Leo Penaloza
8,426 Points

so it continues from where the function last left off?

Steven Parker
Steven Parker
231,269 Points

When the function ends, either by reaching the closing brace or from a "return", the program continues from the point where the function was called.