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 Functions Create Reusable Code with Functions Return a Value from a Function

Why use return within function?

I've watched video over and over and I don't understand why even need to use a return within function.

Without return, it still work same way so why the extra work?

1 Answer

Steven Parker
Steven Parker
229,644 Points

There are two reasons to use "return" in a function:

  • if you want to pass a value back to the caller
  • if you want the function to end before all the code is executed

If you don't need either of these, it's perfectly proper to omit a "return" statement.