I found some SO questions/answers but I am unable to get the async await javascript concept right..please advise ..my question is Should not console.log('end') be executed two times? .
debugger;
async function withoutAwait() {
console.log('without await')
}
async function withAwait() {
await 0
console.log('with await')
}
console.log('start')
withoutAwait()
withAwait()
console.log('end')
credit to question goes to Konrad Linowski:async await)
No, the console.log('end')
will not be executed two times. The Javascript is synchronous. That means that every instructions are executed one after another. With the keyword async
you indicate that you want to execute once the instruction is finished.
If your function withAwait
takes 25 seconds, then your console.log('with Await')
will be fired 25 seconds after. Meanwhile the console.log('end')
will be fired right after calling your function.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments