1 The advance of the variable does not mean that the assignment is advanced. If the variable a is advanced, the value of a is undefined, and the function with the same name is advanced, the variable A will be overwritten and the value of a will be function.

      var a;
      a=()=>{
          console.log(11)
      };
      console.log(a);
Copy the code

2 change the declaration position of variable A, the result is the same. The reason: variable promotion does not involve variable copy promotion.

     a=() = >{};
     var  a;
     console.log(a);
Copy the code

The value of A is still a function.

* You can also assume that the value of the function overrides the variable when declaring and displaying the function.

For variable overrides: just for redeclaring variables.*

In the same scope, there is worth overwriting, functions overwriting variables; Variable overwrites variable; Function overrides function. Different scopes do not overwrite.Copy the code
     var k=2;
    console.log(k);
     m=() = >{console.log(131231)};
     var m;
     console.log(m);
     n=() = >{console.log(1)};
     n=() = >{console.log(2)};
     console.log(n);
Copy the code

If you overwrite, you cannot redeclare variables and call changes directly

     var  cl1=22;
     dd1=() = >{
         cl1=33;
     };
     dd1();
     console.log(cl1);
Copy the code

If you do not add var to a declared variable, it will start to see if the variable exists in the current scope. If it does not, it will continue to look for the variable in the upper scope. If it does, it will overwrite it. If not at the end. The variable is mounted in the Window object as a property or method. As a global variable, we can call it directly or use the window. variable name directly

If you don't add to the declaration variablevarIf not, go up to the next level of scope. If so, overwrite it. If not, go up to the top level of scope. If not at the end. Will mount the variable in thewindowIn the object. fn=() = >{
         a=2;
     };
     fn();
     console.log(window.a)
Copy the code

In the case of a parameter in a function, it is equivalent to declaring a variable in the function’s local scope. Identifiers of the same name in different scopes are not overwritten.

A parameter in a function is equivalent to declaring a variable in the function's local scopevarThe variable name. Identifiers of the same name in different scopes are not overwritten.var cc;
      cc=123;
      cc1=(cc) = >{// redeclare a variable in the function's local scope. var cc;
          cc=2123;// reassign the parameter cc. Arguments [0]=2123 same effect.
          console.log(cc); }; cc1(cc); Note that a value is passed when a function is called to pass a parameter. Values are passed for primitive types. For objects, passing is a memory address, not a reference.11     console.log(cc);
Copy the code