Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

1.

Definition:
• An async function is declared with the async keyword before the
function declaration or function expression.
2. Asynchronous Operations:
• Inside an async function , you can use the await keyword to pause the
execution of the function until an asynchronous operation completes.
• Asynchronous operations typically involve tasks like fetching data from a
server, reading from a file, or waiting for a timer to expire.
3. Return Value:
• An async function always returns a Promise. If the function returns a
value, the Promise will be resolved with that value. If the function throws
an error or rejects a Promise, the Promise returned by the async
function will be rejected with that error.
4. Error Handling:
• You can use try...catch blocks to handle errors within an async
function . Errors thrown inside an async function are caught and
handled just like synchronous errors.

You might also like