Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre What Is Synchronous Execution? | Foundations of Asynchronous JavaScript
Asynchronous JavaScript Explained

bookWhat Is Synchronous Execution?

When you write JavaScript code, the engine executes statements one after another in a step-by-step manner. This is known as synchronous execution. In synchronous execution, each line of code must finish running before the next one starts. This blocking behavior means that if a statement takes a long time to complete, everything else—including UI updates, user input, or other logic—has to wait until that statement finishes. JavaScript, by design, runs on a single thread, so only one operation happens at a time.

1234567
console.log("Start"); for (let i = 0; i < 1e9; i++) { // Busy loop to simulate a long-running task } console.log("End");
copy

In the code above, when the browser or Node.js runs the for loop, the entire program is blocked until the loop completes. If this code runs in a browser, the page becomes unresponsive—you cannot click buttons or interact with the UI until the loop finishes. This happens because JavaScript is busy executing the loop and cannot process anything else at the same time.

This blocking behavior creates major problems in interactive applications. If you perform time-consuming operations synchronously, your users might experience frozen screens, delayed responses to clicks, or even browser warnings about unresponsive scripts. As a result, understanding synchronous execution is essential for writing responsive and user-friendly JavaScript applications.

question mark

Which of the following best describes synchronous execution in JavaScript?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 1

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Suggested prompts:

Can you explain how to avoid blocking the UI in JavaScript?

What are some alternatives to synchronous execution in JavaScript?

Why does JavaScript use a single thread for execution?

Awesome!

Completion rate improved to 3.57

bookWhat Is Synchronous Execution?

Glissez pour afficher le menu

When you write JavaScript code, the engine executes statements one after another in a step-by-step manner. This is known as synchronous execution. In synchronous execution, each line of code must finish running before the next one starts. This blocking behavior means that if a statement takes a long time to complete, everything else—including UI updates, user input, or other logic—has to wait until that statement finishes. JavaScript, by design, runs on a single thread, so only one operation happens at a time.

1234567
console.log("Start"); for (let i = 0; i < 1e9; i++) { // Busy loop to simulate a long-running task } console.log("End");
copy

In the code above, when the browser or Node.js runs the for loop, the entire program is blocked until the loop completes. If this code runs in a browser, the page becomes unresponsive—you cannot click buttons or interact with the UI until the loop finishes. This happens because JavaScript is busy executing the loop and cannot process anything else at the same time.

This blocking behavior creates major problems in interactive applications. If you perform time-consuming operations synchronously, your users might experience frozen screens, delayed responses to clicks, or even browser warnings about unresponsive scripts. As a result, understanding synchronous execution is essential for writing responsive and user-friendly JavaScript applications.

question mark

Which of the following best describes synchronous execution in JavaScript?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 1
some-alt