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 Giving Information to Functions

Isabel Janssen
Isabel Janssen
5,132 Points

Multiple Return Values, why?

In the last quiz, it said that if you ut mitlble return values in a function only the first one will run. BUT never the less it's possible to store more return values in a function. When you this by useful, and why do people want to store multiple return values in a function if only the first one will run?

1 Answer

A function could have a conditional that returns something based on its result. So, it has multiple return values, but only one of them will ever run

function hi(x) {
  if (x === 5) {
    return 'ya'
  } else {
    return 'nah'
  }
}

Let me know if this helps here