Search code examples
javascriptasync-awaites6-promise

Does "return await" makes any difference?


Is there any difference between

const foo = async () => {
  // some other code that uses await
  return await bar()
}

and

const foo = async () => {
  // some other code that uses await
  return bar()
}

Where bar is a function that returns a promise.

Is the await redundant or does it make any difference?


Solution

  • It is redundant.

    It extracts the value from the promise returned by bar, and then resolves the promise returned by foo with it.

    If you return bar's promise directly, then the promise returned by foo adopts it to the same effect.