What we’ll discuss →
Async functions vs Sync functions
- The real use of
callbacks
- JS Browser Architecture
Promises
- Async
await
Async vs Sync →
Synchronous functions →
- One after the other
- Sequential
- Only one thing is happening at a time
Asynchronous functions →
- Happening in parallel
- In parts
- Multiple things are context-switching with each other
Intuition →
<aside>
💡 The human body and brain are single-threaded; we can only do one thing at a time
</aside>
- But, we can context switch between tasks,
- or we can delegate tasks to others
The same is true for JavaScript
Suppose you have 4 tasks →
- Boil water
- Cut vegetables