JavaScript Introducing ES2015 Classes Sub-Classes

1 Answer

Steven Parker
Steven Parker
170,377 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
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
170,377 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.