Chapter XVI · Asynchronous JavaScript
Synchronous JavaScript
Synchronous JavaScript executes code line-by-line in a strict sequential order where each operation must complete before the next begins.
01 How It Works
Think of a single-lane highway tunnel where cars must pass through one single file in order.
Operations run directly on the single call stack. If a task takes too long, subsequent code execution is blocked.
example.js
console.log("Task 1");
console.log("Task 2");
console.log("Task 3");
1. Statement 1 executes on call stack and finishes.
2. Statement 2 executes on call stack and finishes.
3. Statement 3 executes on call stack and finishes.
02 Practical Example
Here is how you might see this concept applied in real-world code:
practical.js
const result = 5 + 5; // Evaluated synchronously immediately
console.log(result);
Key Takeaway
Synchronous code is blocking and executes in predictable top-to-bottom order.