Await is the new black
Aurélien Hervé
1877

Great article!

It’s worth noting that the promises2.js and promisesbis.js examples aren’t quite equivalent. In promises2.js, the last then function will invoke finalResult but not return that value, whereas promisesbis.js uses a one line arrow function would return the return value of finalResult(user, result).

So for example, in promises2.js if you invoked demoPromise().then, you wouldn’t receive any result and it would return immediately after invoking finalResult, even if it was also an asynchronous operation. Whereas in promisesbis.js, demoPromise().then would potentially return some value after finalResult has completed executing.

That said, there may be cases where you don’t want to return something from a promise, but to make them equivalent either promises2.js should return finalResult(user, result) or promisesbis.js should wrap the finalResult statement in braces, making it so it doesn’t return the result:
 
 .then(([user, result]) => { finalResult(user, result) });

Like what you read? Give Cooper Filby a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.