Scope
1. Global Scope
let globalVar = "I am global";
function checkScope() {
console.log(globalVar); // Accessible here
}
checkScope();
console.log(globalVar); // Accessible here too2. Local Scope
function checkScope() {
let localVar = "I am local";
console.log(localVar); // Accessible here
}
checkScope();
console.log(localVar); // Error: localVar is not defined3. Block Scope
4. Function Scope
5. Lexical Scope
6. Scope Chain
Help us improve the content 🤩
Last updated