To understand scope it is important to understand about blocks.
A block is code that is found inside a set of curly braces {}
. Blocks help us group one or more statements together and serve as an important structural marker for our code. You will see them in many places, including if statements and functions.
A block of code could be a function, like this:
const favColour = () => {
let colour = 'silver';
console.log(colour);
}
This function body is a block of code.
A block of code can be an if
statement:
if (morning) {
let wake = 'yes';
console.log(waker);
}