𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀, 𝗧𝗵𝗿𝗲𝗮𝗱𝘀, 𝗮𝗻𝗱 𝗔𝘀𝘆𝗻𝗰𝗵𝗿𝗼𝗻𝗼𝘂𝘀 𝗘𝘅𝗲𝗰𝘂𝘁𝗶𝗼𝗻

You need to understand how JavaScript works under the hood.

Here is a breakdown of functions, processes, threads, and execution styles.

𝗞𝗶𝗻𝗱𝘀 𝗼𝗳 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀

𝗣𝗿𝗼𝗰𝗲𝘀𝘀 𝘃𝘀. 𝗧𝗵𝗿𝗲𝗮𝗱

A Process is a program running on your computer.

A Thread is a small unit inside a process.

𝗦𝘆𝗻𝗰𝗵𝗿𝗼𝗻𝗼𝘂𝘀 𝘃𝘀. 𝗔𝘀𝘆𝗻𝗰𝗵𝗿𝗼𝗻𝗼𝘂𝘀

JavaScript is single-threaded. It handles one task at a time using a call stack.

Synchronous Execution:

Asynchronous Execution:

How Asynchronous works:

  1. JavaScript sends a task (like a timer) to a Web API.
  2. The main code keeps running.
  3. Once the task finishes, it moves to the Callback Queue.
  4. The Event Loop moves it to the Call Stack when the stack is empty.

This keeps your web apps fast and responsive.

Source: https://dev.to/kamalesh_ar_6252544786997/types-of-function-and-threads-process-and-synchronous-vs-asynchronous-in-javascript-1hhd