search

Home  >  Q&A  >  body text

javascript - Async function in js returns a promise, what does await return?

For example var r = await fetch(url);Is reeponse returned? r receives response; right

为情所困为情所困2747 days ago546

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-05-19 10:19:28

    Return resolved value. In your example, it is a correct response (2xx).

    try {
      var r = await fetch(url);
    } catch(e) {
      console.error(e);
    }

    catch Capture the reject value, which is an exception.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-19 10:19:28

    expression is a Promise, resolved, returns the resolved value; rejected, throws an exception.
    Not a Promise, returns a resolved Promise.

    await-mdn

    reply
    0
  • Cancelreply