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
MOD
Michael Hulet
Treehouse Moderator 47,639 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.