DEV Community

Discussion on: A key difference between .then() and async-await in JavaScript

naimadozodrac profile image

It was my understanding that async ensures that a function returns a promise by creating a new Promise only if a "thing" within the function is not a Promise.

I think this is not exactly accurated. We are getting a promise, which resolves with the same value as the promise from the return statement but is not true that the exact same object is returned, not even when there is already a promise, it is a new one.

const p = Promise.resolve('foo');

async function foo() {
return p;
p === foo(); // false

BTW the article is super nice, thank you

Thread Thread
sainig profile image
Gaurav Saini • Edited on

Oh, didn’t know it worked that way. Thanks for your input @naimadozodrac

Again as we find out, the devil lies in the details