1, variable promotion: As long as the variable is declared in the code, no matter where it is declared, the JS engine will put its declaration at the top of the scope;
// undefined var A;
2, function Promotion: As long as the function is declared in the code, no matter where it is declared, the JS engine will put its declaration at the top of scope scopes;
// function B () {} function B () {};
As you can see, a variable or function declaration is not placed at the top of the current scope, so the question is: if the variable and function have the same name, is it ripe and heavy? Who has a higher priority level?
varA;functionA () {};console.log (a);//function A () {}functionB () {};varB;console.log (b);//function B () {}varC=1;functionC () {}console.log (c);//1functiond () {};varD=1; Console.log (d);//1
Summary: When variable declarations and function declarations have duplicate names,
Regardless of the order in which they are declared, the function declaration overrides the variable declaration, that is, when the value of a is declared function A () {}.
Note: If a is initialized at the same time as a variable declaration, or a is subsequently assigned, the value of a is the value of the variable.
In other words: a===undefined? a=== function: a=== variable
Things that are easy to ignore (variable elevation and function elevation)