Scope
Where a name is visible: global, function, and block scopes.
A let or const declared inside { } exists only in that block.
Function parameters and let/const inside a function stay inside that function.
Outer names are readable from inner scopes unless shadowed.
Results appear here.
Important JavaScript
const appName = "Scope Lab"; // global for this script
function describe() {
const label = "inner"; // function scope
return appName + " / " + label;
}
if (true) {
const blockOnly = "block"; // block scope
console.log(blockOnly);
}
// console.log(blockOnly); // ReferenceError
const score = 10;
if (true) {
const score = 99; // shadows outer score inside this block
console.log(score); // 99
}
console.log(score); // 10