Lesson 5.1: Asynchronous JavaScript – Callbacks, Promises, async/await
Asynchronous JavaScript allows code to run without blocking the execution, making web applications faster and more responsive.
1. What is Asynchronous JavaScript?
-
Normally, JavaScript runs synchronously – one line at a time.
-
Asynchronous code lets tasks like API calls or timers run in the background while other code continues.
2. Callbacks
-
A callback is a function passed as an argument to another function, executed after a task completes.
3. Promises
-
Promises handle future values from asynchronous operations.
-
States:
pending,fulfilled,rejected.
4. Async / Await
-
Async functions always return a promise.
-
Await pauses the function until the promise resolves.
5. Practical Use
-
API calls, timers, file reading, or any task that takes time.
-
Makes websites fast and responsive without freezing the UI.
✅ Summary:
-
Callbacks: Functions passed to execute later.
-
Promises: Handle asynchronous operations with
.then()and.catch(). -
Async/Await: Modern, clean syntax for promises.
-
Essential for fetching data, APIs, and real-world web apps.
