await

turns Promise (future value) into a value/error.

(⭐️ ES2017) (primary expression) (unary operator) turns a Promise / thenable into a return value / thrown exception.

  • if resolves normally, await returns the result.

  • if rejected, it throws error (as if there were a throw statement at that line).

// works only inside async functions❗️ 
let value = await promise;
// when top-level await not supported, use async IIFE instead.
(async () => {
  let value = await promise;
  // ...
})();

Last updated