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!

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 Basics (Retired) Creating Reusable Code with Functions Review: Getting Information from Functions

Yifang kuo
Yifang kuo
Front End Web Development Techdegree Student 12,376 Points

Why the answer is not Friday

After the code below runs, what value is stored in the variable dayOfWeek: function getDay() { return "Monday"; alert("Calculating day"); return "Friday"; }

var dayOfWeek = getDay();

4 Answers

Nattapol Kamolbal
Nattapol Kamolbal
15,528 Points

As soon as the function encounters a return statement it exits the function and returns a value.

xufan liu
xufan liu
1,121 Points

so the second return does not run ? what is the second return for then?

Joshua Ouma
Joshua Ouma
20,651 Points

Because the program stopped and exited the function when it encountered the first return statement and then returned its value

as far as I know it doesn't return nothing but a "undefined". Hypothetically the first return the second is to through you of and it also doesn't come up as syntax error either.

It will return "Monday"