Synchronous Code

One Line at a Time

Synchronous code runs line by line; each line waits for the previous one to finish. JavaScript has one main thread, so a slow synchronous task blocks everything else (clicks, rendering).

Example

console.log('1. Start');
for (let i = 0; i < 1e7; i++) {} // slow work blocks the thread
console.log('2. Loop done');
console.log('3. End');

Output

1. Start
2. Loop done
3. End