𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗦𝗰𝗼𝗽𝗲: 𝗕𝗹𝗼𝗰𝗸, 𝗚𝗹𝗼𝗯𝗮𝗹, 𝗮𝗻𝗱 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻

Scope decides where you use a variable in your code.

  1. Global Scope Variables live outside functions or blocks. You access them from anywhere in your script. Warning: Global variables lead to bugs because any part of your code can change them.

  2. Function Scope Variables live inside a function. You only access them within that specific function.

  3. Block Scope This applies to modern JavaScript using let or const. Variables live inside curly braces {}. A block includes:

Summary of Scope:

Understanding Processes and Threads

A process is a running program with its own memory. Think of WhatsApp as a process.

A thread is a small part of a process. Threads share the same memory.

Example of WhatsApp: One process (WhatsApp) runs multiple threads:

Source: https://freeacademy.ai/lessons/global-vs-function-vs-block-scope Source: https://josephcardillo.medium.com/the-difference-between-function-and-block-scope-in-javascript-4296b2322abe