To begin, we are reminded that we have seen blocks before in the function section as well in if conditionals. A block of code is simply a set of statements enclosed within a pair of curly braces. Blocks help us group together one or more statements, and they serve as important structural markers of our code. A block of code can be a function or even the part of an if condition that runs if the condition is true.
We learn that variables declared using the let and const keywords are block-scoped, meaning they are only accessible within the block in which they are declared. This is different from variables declared with the var keyword, which have function-level scope and can be accessed throughout the function in which they are defined.
We are also introduced to the concept of global scope, which refers to variables that are declared outside of any function or block. Global variables can be accessed from anywhere in our code, making them powerful but also potentially dangerous. It’s generally best practice to avoid global variables when possible, as they can lead to unexpected behavior and difficult-to-debug issues.