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

When you call noAlert() function for the second time, why the value (5) is not returned again?

Is it something about the RETURN key, that only returns value once. I am confused for seeing the alert box and not seeing the value 5 returned. The case is shown in the end of this video (https://teamtreehouse.com/library/using-multiple-return-statements#questions)

3 Answers

That's because he is running it in the console and he has a second function right after it alert(), the alert function doens't return anything, therefore you see undefined.

Thank you. But why noAlert() function is not called for the 2nd time. It is well defined. Or it has to do sth with the console?

it is actually called, as you can see by the alert window popping up. You just don't see the return statement because the console ignores it.

Thanks Zimri Leijen :)

Zimri Leijen wrote:

it is actually called, as you can see by the alert window popping up. You just don't see the return statement because the console ignores it.

I don't really understand why the console ignores the return statement from the noAlert() function here. Could someone explain what is happening here or point me in the right direction to learn more about this?