Async/await is a cleaner, simpler way to handle Promises in JavaScript. It makes asynchronous code look and behave like synchronous code.
`async function greet() { return "Aman"; }
console.log(greet()); // Promise { 'Aman' }`
async Before a function, it automatically wraps the return value in a Promiseasync function getData() { const response = await fetch('<https://api.github.com/users>'); const data = await response.json(); console.log(data); }
What await does:
`// β BAD - Don't use await at top level (freezes entire program) const response = await fetch(url);
// β GOOD - Wrap in async function async function fetchData() { const response = await fetch(url); }`
Why? If you use await outside an async function, your entire program freezes waiting for the result.