Asked 6 years ago
24 Mar 2018
Views 14985
jaggy

jaggy posted

SyntaxError: await is only valid in async functions and async generators


function AsyncCall() {
  let promise = Promise.resolve(1);
  let result = await promise;
}
AsyncCall();


SyntaxError: await is only valid in async functions and async generators

TypeError: AsyncCall is not a function[Learn More]
angeo

angeo
answered Nov 30 '-1 00:00

right way is put async before function .


async  function AsyncCall() {
  let promise = Promise.resolve(1);
  let result = await promise;
}
AsyncCall();


await only works inside async function.
Post Answer