The correct answer is D , because JavaScript executes synchronous code first, while the code after await runs later after the Promise resolves.
The execution order is:
console.log(2);
This runs first, so JavaScript logs:
2
Then this line runs:
asyncCall();
The asyncCall() function starts executing. Inside it, JavaScript reaches:
await delay(1000);
The delay(1000) function returns a Promise that resolves after 1000 milliseconds:
return new Promise(resolve = > {
setTimeout(resolve, delay);
});
Because await pauses the rest of the asyncCall() function, this line does not run immediately:
console.log(1);
Instead, JavaScript continues executing the remaining synchronous code outside the async function:
console.log(3);
So JavaScript logs:
3
After approximately 1000 milliseconds, the Promise returned by delay(1000) resolves. Then the paused async function continues and runs:
console.log(1);
So JavaScript logs:
1
Final console output:
2
3
1
Important JavaScript concepts involved:
An async function always returns a Promise.
The await keyword pauses execution only inside the async function where it appears.
Code outside the async function continues running normally.
setTimeout() schedules its callback to run later, after the current synchronous code has finished.
Therefore, the verified answer is D. 2 3 1 .
Submit