0

Why method b excuted before method a ?

And what i do that method a be excuted before method b?

const a = () => {
   setTimeout(function(){console.log("method a excuted")},10000)
}

const b = () => {
   console.log("method b excuted");
}

const s = async () => {
    await a();
    await b();
}


s();
result:
method b excuted
method a excuted  //after 10 second
hossein ketabi
  • 480
  • 7
  • 19
  • 2
    `await` only makes sense when the right-hand side is a Promise – CertainPerformance Feb 03 '20 at 07:22
  • `a` is executed before `b` in your code but the callback passed to `setTimeout` is executed later. `await` waits for the value returned by `a` to be resolved, and you return `undefined` from `a`. – t.niese Feb 03 '20 at 07:24

0 Answers0