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 Using Multiple return Statements

I am curious as to why the noAlert() function does not return a value in the latter part of the code snippet.

I understand why the alert is never called in the function, and why it is called outside of the function....but I cannot figure out why calling the alert function immediately after the noAlert() function prevents the noAlert() function from returning a value.

1 Answer

Steven Parker
Steven Parker
229,744 Points

The noAlert function does still return a value, but the nature of the console is to display only the value returned by the last operation performed. So when the alert is executed, the previous return value is forgotten and the value it returns ("undefined") is the only thing displayed.