Welcome to the Treehouse Community
Looking to learn something new?
Omar Farag4,571 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 BuffingtonCourses Plus Student 8,037 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.