Scope is a collection of accessible variables.
Variables are declared inside functions, and variables are locally scoped.
Local variables: accessible only inside functions.
Because local variables only work inside functions, different functions can use variables with the same name.
Local variables are created when the function starts executing, and local variables are automatically destroyed after the function is executed.
Variables are defined outside functions, that is, global variables.
Global variables have Global scope : All scripts and functions in the webpage can be used。
If a variable is not declared inside a function (without using the var keyword), the variable is a global variable. In the following example, carName is inside the function, but is a global variable.
Local variables are destroyed after the function finishes executing.
Global variables are destroyed after the page is closed.
Function parameters work only within functions and are local variables.