Hint
Global, function (local), and block scope — each has different variable rules
JavaScript has three types of scope:
window.var inside a function are only accessible inside that function.let or const inside {} are scoped to that block.var globalVar = 'everywhere';
function fn() {
var funcVar = 'function only';
if (true) {
let blockVar = 'block only';
var leaky = 'leaks to fn scope'; // var ignores blocks!
}
console.log(leaky); // ✓ 'leaks to fn scope'
console.log(blockVar); // ✗ ReferenceError
}
console.log(funcVar); // ✗ ReferenceError
The scope chain: When a variable isn't found in the current scope, JS looks up to the outer scope — all the way to global. Inner scopes access outer variables; outer scopes cannot access inner.