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 trialPhilip Kroupoderov
Front End Web Development Techdegree Graduate 21,641 Pointswhy the return statement has no value?
He is writing return followed by no value. What does that do and why???
1 Answer
Steven Parker
231,275 PointsNot all functions need to return a value. But you can still use a "return" to cause the function to stop running and return to the caller. A typical reason to do this would be inside an "if" block to end the function without peforming the code that comes after.
If that doesn't completely explain it, please name the function and give a video time index where the return is added.
Philip Kroupoderov
Front End Web Development Techdegree Graduate 21,641 PointsSteve thanks but I found the answer by playing around with the code and that does not really answer the question. You can break out of a function by returning any falsy value: false, 0, null, undefined, Nan. When a return statement has no value it returns undefined.
Steven Parker
231,275 PointsYes, but you would not use a "return" with no value unless the function never returns any value. Also a "return" will always end the function, whether the returned value is truthy, falsey, none at all (undefined).
Please name the function and give a video time index where the return is added if this doesn't answer the question completely.
Tristan Magpantay
Full Stack JavaScript Techdegree Student 14,032 PointsTristan Magpantay
Full Stack JavaScript Techdegree Student 14,032 PointsWhat's the code?