Scope determines where a variable can be read. Variables declared inside a function stay local to that call, while let and const inside a block are unavailable once the block ends.
const unit = "points";
function formatScore(score) {
const label = `${score} ${unit}`;
return label;
}
console.log(formatScore(9)); // 9 points
// console.log(label); // ReferenceErrorSmall tracing exercises reveal function and block scope, accidental shadowing, and out-of-scope access. Keeping values in the smallest useful scope reduces surprising interactions elsewhere in a program.