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
saif ahmad
9,302 Pointsreturn statement
hey ! i know what a return statement does but can it only be used inside a function?! Where do we use it ?!
1 Answer
andren
28,558 PointsThe return statement is used to return data from a function to the code that called it, so by its very definition it can only be used within a function.
It's worth nothing that once a function returns it stops running, so the return statement should generally be the last thing in your function, unless it is placed within an if statement or something like that.