JS --- function names and variable names the same name

Continue scope of the problem, this morning, for a moment, watching the afternoon saw a type of title, function names and variable names the same problem. Before you will not feel the same name as the function names and variable names there will be no conflict. Also did not go to tested. . Lazy. Directly attached to the code:

After running all the guess is how much? Breath: 100! ! I really was big tone, did not think the direct answer, it is not a good habit.

Unexpected error, and feeling a little confused. But step by step to analyze, then you can understand why this is the answer.

This question needs first stage of pre-compiled and linked JS, and context that is, before the implementation of the code, need to be prepared; be prepared in the pre-compilation stage need to use variables, functions, and other resources.

Variables and variable expression obtained in the stage of pre-compiled statement, and no assignment, get undefined;

Declarative function obtained in the pre-compilation stage is an assignment, yes, that is a direct assignment.

And the order is ready to have the resources, the first pre-compiled parameters> Functions> variables;

To pre-analytical functions and variables:

1) function declaration will top
2) variable declaration will top
3) function declaration is more sticky than the variable declaration :( function in the variable above)
4) variables and assignment to write together, when js parsing engine, which will be split into statement and assignment part 2, set-top statement, the assignment remains in its original position
declared 5) variable declaration does not repeat

 

So this question can be resolved as follows:

This time we can understand why a good () The result is a function not being given a say, and people already have is not the function has been re-assigned values ​​defined types, of course, be given slightly.

Evey life has it's roses and throns

 

 Reprinted: https://www.cnblogs.com/Trista-l/p/7382135.html

       https://www.cnblogs.com/bugda/p/6036282.html

 

This time we can understand why a good () The result is a function not being given a say, and people already have is not the function has been re-assigned values ​​defined types, of course, be given slightly.

Guess you like

Origin www.cnblogs.com/taohuaya/p/11129729.html