The async
keyword is used to declare an asynchronous function that returns a Promise, while await
is used to pause the execution until the Promise is resolved. This syntax simplifies the handling of asynchronous code. Example:
const fetchData = async () => {
const response = await fetch('https://api.example.com/data');
const data = await response.json();
console.log(data);
};
fetchData();