𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀, 𝗣𝗿𝗼𝗰𝗲𝘀𝘀𝗲𝘀, 𝗮𝗻𝗱 𝗘𝘅𝗲𝗰𝘂𝘁𝗶𝗼𝗻

Mastering JavaScript requires understanding how code runs.

Here are the core concepts you need to know.

𝟭. 𝟱 𝗧𝘆𝗽𝗲𝘀 𝗼𝗳 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀

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

A Process is a running program. Each process has its own memory. If Chrome crashes, Spotify keeps running because they are separate processes.

A Thread is a small unit inside a process. Threads share the same memory. This makes them faster and lighter than processes.

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

JavaScript is single-threaded. It usually runs one task at a time.

Synchronous Execution: Tasks run in a strict order. The next line waits for the current line to finish. This can slow down your app if a task takes too long.

Asynchronous Execution: Tasks can start now and finish later. This prevents your code from blocking.

How it works:

Example of Asynchronous flow:

  1. Log "Hi"
  2. Start a timer for 2 seconds
  3. Log "End"
  4. (2 seconds pass) Log "Vicky"

The code does not wait for the timer. It moves to "End" immediately.

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

Optional learning community: https://t.me/GyaanSetuAi