Skip to content Skip to sidebar Skip to footer

Js Promises: If A Handler In A `then` Block Returns A Value Vs Returning A Resolved Promise, Does The `then` Block Handle It The Same Way?

Say I have a function that returns a resolved promise like this: let a = () => {return new Promise(res => res(1))} and then I then-ify it like this: a() .then(val => {ret

Solution 1:

All values returned from a then block are implicitly wrapped in a Promise.resolve, so returning Promise.resolve(1) is unnecessary.


Post a Comment for "Js Promises: If A Handler In A `then` Block Returns A Value Vs Returning A Resolved Promise, Does The `then` Block Handle It The Same Way?"