Mikolaj Stankowiak
1 min readMay 31, 2019

--

I do not think this is accurate. Whilst it shows the general principle — we are getting a promise, which resolves with the same value as the promise from the return statement — it is not true that the exact same object is returned.

const p = Promise.resolve('foo');                                               async function foo() {
return p;
}
p === foo(); // false

If you think about it, an async function has to return something before the final return is reached (so that part of the function can run later on asynchronously). Apparently JS does not know and cannot predict (can it?) what will be returned when entering a function, so it has to return a new Promise.

Please do correct me if I am wrong, but these are the results I am getting.

--

--