Category: javascript
Async functions
Published on 16 Jul 2026
Explanation
Async functions allow asynchronous code to be written like synchronous code.
Code:
async function load() {}
Explanation
The await keyword pauses execution until the Promise resolves.
Code:
const res = await fetch(url);
Explanation
Await can only be used inside async functions.
Code:
async function getData(){
const data = await fetch(url);
}
Explanation
Async/await improves readability over chained promises.
Code:
const data = await res.json();
Explanation
Errors should be handled using try...catch.
Code:
try {
await fetch(url);
} catch(err) {}