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 Introducing ES2015 Classes Sub-Classes

1 Answer

Steven Parker
Steven Parker
231,275 Points

Not 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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Philip Kroupoderov
Front End Web Development Techdegree Graduate 21,641 Points

Steve 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
Steven Parker
231,275 Points

Yes, 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.