Global function scope (put the declaration of the variable and the declaration of the function in front)
Scope: The scope in which a piece of data can be used. In general, the data used in a program code is not always valid/available, and the scope of the code that qualifies the availability of the data is the name. The use of scopes improves the locality of the program logic, enhances the reliability of the program, and reduces the name collisions.
Variable (data) JS, the scope of the variable is two, one is the global scope (global variable), a local scope (local variable), a variable is a global variable or a local variable, mainly see the position of the variable declaration. Declared inside a function, is the local variable of this function.
Global scope---Anywhere access to a variable defined outside of a function that has global scope does not use VAR to define a variable that has global scope all properties on a Window object have global scope not declared within any function that has global scope local scope---can only be accessed within the function Variables defined inside a function using VAR, and functions declared inside a function using function, have local scope
See Scope for details
Output: Zhangsan
Equivalent
2. Execution can also be done before the definition
This and arguments will determine the value before execution
Scope Chain
[[Scopes]]: scope When we declare a function, and the function creates a property that is [Scopes], the variable that we declare in this function is stored in the function's [[Scopes]] property in the lookup rule for variables and functions: When we call a piece of data, JS will first look in the current scope, if not found, to find the scope of the parent, if not found in the scope of the parent, continue to look up until the scope of the window. If you can't find it in the window, it's an error.
JS (global scope)