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 Asynchronous Programming with JavaScript Understanding Promises From Callbacks to Promises

Using `return` keyword with `resolve` and `reject` callbacks

Since resolve and reject are essentially callbacks, could we use return resolve(data); instead of just resolve(data); as we did before within callbacks topic. The same applies to the reject callback. Thanks in advance. Guil Hernandez

1 Answer

Michael Hulet
Michael Hulet
47,912 Points

You definitely can use the return keyword before those calls if you'd like. Since you're right that reject and resolve are just callbacks in the same way that the previous implementation had a callback, in this specific instance, it won't do anything than what the original callback version was doing. It didn't really do anything in either case, because the calls to callback, reject, and resolve were all at the end of their functions, anyway. Be a little bit careful when you do this, though, because the return keyword signals to JavaScript that the current function should end its execution immediately, though that's most often what you want to do when you call resolve or reject.