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
Omar Farag4,573 Points
How many values can the "return" keyword return?
In the video before this one, the instructor says that the "return" keyword can only return one value. However, in this video, he returns 3. Any explanations?
Rick Buffington8,146 Points
He is correct, a function can only return one value/type. Where you might be getting hung up is when he is returning multiple variables that make up 1 single value. For example:
return "This is a string"; // This is 1 value
var name = "Dude"; return "Hi " + name; // This is still 1 value (a string that returns "Hi Dude"), using a variable
var firstName = "Dude"; var lastName = "Awesome"; return "Hi " + firstName + " " + lastName; // This is still 1 value (a string that returns "Hi Dude Awesome"), using 2 variables
So, as you can see you can return only 1 value, but that value can be made up from several variables of the same type. In this case multiple variables put together to return a String.