A scope, also called an execution environment, controls which variables and functions can be accessed by a program. There are two types of scope (execution environment) in JS: global scope and function scope
Global scope:
Properties and methods that can be accessed anywhere in the code, such as the built-in properties of the Window object, are in the global scope
Function scope
Only code snippets inside the function can access properties and methods, or variables and methods declared inside the function
A scope has a hierarchical relationship. The scope in which a function is created is its parent scope
The most important feature of scopes is the isolation of variables. Different scopes can define variables with the same name
The value of a variable is taken from the current scope. If it cannot be taken, it is taken from the parent scope. The value chain thus formed is called the scope link