1. What Is Synchronous Code?

Synchronous code is code that executes one instruction at a time, in a specific order.

JavaScript executes synchronous code line by line. The next instruction generally waits until the current instruction has finished executing.

Example

console.log("First");

console.log("Second");

console.log("Third");

Output:

First
Second
Third

How does it work?

  1. JavaScript executes the first console.log().
  2. After it finishes, JavaScript executes the second console.log().
  3. Finally, JavaScript executes the third console.log().

Each instruction waits for the previous one to complete.

Another example

console.log("Start");

let result = 10 + 20;

console.log(result);

console.log("End");

Output:

Start
30
End

Important Points