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

Christian Solorzano
Christian Solorzano
6,606 Points

What's the purpose of having multiple values?

What's the purpose of having multiple values in a function? For example, a return, an alert and a second return?

1 Answer

Kelly von Borstel
Kelly von Borstel
28,880 Points

I don't know if this will answer your question, but one reason you might have multiple return statements is if you want to return different values based on the result of a conditional statement. The following function is an example — it takes two numbers and returns the smaller of those two numbers.

function minValue(num1, num2) {
  if (num1 < num2) {
    return num1;
  }
  else {
    return num2;
  }
}