DEV Community

Cover image for JavaScript: Synchronous or Asynchronous?
Anandteerth Onkar
Anandteerth Onkar

Posted on

1

JavaScript: Synchronous or Asynchronous?

Understanding the Synchronous and Asynchronous operations:

In synchronous operations, operation are performed one at a time. The next operation is unblocked only when the ongoing operation is completed.
Simple words, you need to wait for a operation in progress to finish, in order to start the next one in the queue.

In asynchronous operations, the next operation can be started before the previous one finishes.
Asynchronous programming allows to handling of multiple requests simultaneously, thereby allowing to accomplish more tasks within shorter time span.

So what is JavaScript?

At its core, JavaScript is by default Synchronous in nature.

Let's break it down:
It is Synchronous because it is Single-threaded. In single-thread one operation is executed at a time.
It blocks other operations in queue, as they need to wait until the previous operation has completed execution.

In nutshell:
In JavaScript, only one operation will be executed at a time and the successive operations in stack need to wait until the ongoing operation is completed.

Question: If JavaScript is Synchronous in nature, why on this earth Asynchronous JavaScript term so popular amongst JavaScript developers?

Answer: The developers manipulate JavaScript to behave Asynchronously. To make this manipulation, there are 3 techniques:

  1. Callback function
  2. Promises
  3. Async/Await.

Resources I recommend to understand these asynchronous techniques:

Callbacks:
Watch this awesome video by Philip Roberts while referring to his Demo website

Callback Hell: Callback Hell is a Nightmare. Refer this if you want to dig deeper into callbacks

Promises:
Video by Codevolution

Async/Await:
Best article on this topic by Mostafa Gaafar

All 3 techniques in one video by codeSTACKr


I will be creating articles on each of these topics. Need feedback from bloggers & readers of dev community, that will help me to improve my work.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more