๐—ฆ๐˜†๐—ป๐—ฐ๐—ต๐—ฟ๐—ผ๐—ป๐—ผ๐˜‚๐˜€ ๐˜ƒ๐˜€ ๐—”๐˜€๐˜†๐—ป๐—ฐ๐—ต๐—ฟ๐—ผ๐—ป๐—ผ๐˜‚๐˜€ ๐—๐—ฎ๐˜ƒ๐—ฎ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜

JavaScript runs on a single thread. This means it handles one task at a time. You must understand how it manages different types of tasks to build fast web apps.

Synchronous JavaScript

In synchronous code, tasks run in a specific order. Each line waits for the previous line to finish.

Asynchronous JavaScript

Asynchronous code allows tasks to run in the background. It does not stop your main program from running. This makes your apps feel fast and responsive.

How it works:

Process vs Thread

To understand execution, you should know the difference between processes and threads.

Process

A process is an independent program.

Thread

A thread is a small unit of execution inside a process.

Summary

Use synchronous code for simple, quick steps. Use asynchronous code for tasks that take time, like fetching data. This prevents your website from freezing.

Source: https://dev.to/vidhya_murali_5aabe7784bd/synchronous-and-asynchronous-in-javascript-14ip