Scope = where a variable is accessible (where you can use it)
1.Global Scope
Definition:
Variables declared outside any function or block have global scope
Example:
Problem: Global variables can be changed from anywhere → bugs!
2.Function Scope (Local Scope)
Definition:
Variables declared inside a function have function scope. They are only accessible inside that function
Example:
3.Block Scope(ES6 - Modern JavaScript)
Definition:
Variables declared with let or const inside a block {} have block scope. They are only accessible inside that block
What is a Block?
Any code inside curly braces {}:
ifstatementsforloopswhileloopsStandalone blocks {}
Example:
Key Takeaways:
Global = accessible everywhere (declare outside functions)
Function = only inside function (declare inside function() {})
Block = only inside {} (declare with let/const inside blocks)
var = function scope (NOT block scope)
5.let/const = block scope (modern, preferred)
Process: A running program that has its own memory and resources — like the WhatsApp application
Thread: A smaller part inside a process that shares the same memory — like WhatsApp downloading messages, playing videos, and sending photos at the same time
Thread = Lightweight process
Uses shared memory
Faster to create and manage than a process
Helps perform multiple tasks concurrently
Simple Example:
Process: WhatsApp
Threads inside WhatsApp:
Message receiving thread
Photo sending thread
Video playing thread
Notification thread
One process can contain multiple threads



Top comments (0)