Namaste JavaScript — Interview Quick Notes
Ep 23: async / await
- async before a function makes it always return a Promise (wraps plain values automatically).
- await pauses execution of the async function until the promise resolves — the Call Stack is not blocked.
- async/await is syntactic sugar over .then/.catch — same behaviour, better readability.
- Error handling: use try/catch inside async functions (or .catch on the returned promise).
- Promises start executing immediately when created — await only waits, it does not start them.
1async function fetchUser() {
2 try {
3 const res = await fetch("https://api.github.com/users/alok722")
4 const data = await res.json()
5 console.log(data)
6 } catch (err) {
7 console.error(err)
8 }
9}