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 Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay