Scope is an important concept to understand when using JavaScript. It controls where variables can be accessed or referenced in your code and plays a big role in keeping your programs clean, modular, and bug-free.
When a variable is "in scope," you are allowed to reference it and work with it. When a variable is "out of
scope," trying to access it will cause an error, usually a
ReferenceError.
This is JavaScript's way of saying, "I don't know what you're talking about — that variable doesn't exist here."
{
let blockVariable = "I'm inside a block!";
console.log(blockVariable); // Works fine
}
console.log(blockVariable); // ReferenceError