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 trialLuqman Shah
3,016 PointsYou can have more than one return statement in a function.
I said no to this quiz question, but then I got it wrong and it said "yes, but only one will ever run." So essentially..NO LOL?
2 Answers
Rares Conea
Courses Plus Student 15,000 PointsHi Luqman, You can have as many return statement as you want. Let's say you have an if statement: if(condition){return value1;} else {return value2;}. Here you have 2 return statements but only one will run.
Steven Parker
231,275 PointsYou can have more than one "return" statement, and only one will run for a particular call of the function. There may be conditional tests that would cause a different one to run during a different call.
So these statements are both true and not exclusive.
Luqman Shah
3,016 PointsLuqman Shah
3,016 PointsAhh ok I understand, so yes one will only ever run as it's a conditional statement, but it'll have to be one or the other, since it is a conditional after all? It may be the if statement or the else statement?