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

Why are there two return statements in this Promise callback?

I was following along the "Handle Multiple Promises with Promise.all" lesson, and I noticed that in the example, the teacher placed two return statements. In my experience, the function will stop execution at the first one. So what is the point of the Promise.all() in that function?

https://www.dropbox.com/s/y2sjv38mm9wwh2p/Screenshot%202020-06-24%2022.02.07.png?dl=0

1 Answer

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,850 Points

You actually have two separate functions/methods, one just happens to be nested in another function.

function getProfiles(json) {
   const = profiles.people.map(person => {
       return getJSON(wikiUrl + person.name) // this return is for the callback function within the array map method
   });
   return Promise.all(profiles); // this is the return for the getProfiles function
}