JavaScript Internals (521 Qs)•Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)
What are the different ways to deal with Asynchronous Code
Below are the list of different ways to deal with Asynchronous code.
- Callbacks
- Promises
- Async/await
- Third-party libraries such as async.js,bluebird etc
Practical Code Example
javascript
// Ways to deal with Asynchronous Code:
// 1. Callbacks (legacy): fs.readFile(path, cb)
// 2. Promises: fetch(url).then(res => res.json())
// 3. Async / Await (Modern syntax):
async function getData() {
const res = await fetch('/api');
return await res.json();
}