How does the await keyword work in JavaScript?
a) It pauses the execution of an
async
function until the promise is resolved or rejectedb) It returns a promise
c) It forces a function to execute synchronously
d) It runs a function immediately
Answer:
a) It pauses the execution of an
async
function until the promise is resolved or rejectedExplanation:
The await
keyword is used inside an async
function to pause execution until a promise is resolved or rejected. This allows asynchronous code to be written in a synchronous style.