Talking about the variable name and function name in js, talking about the js function name duplication
Today, skokai asked a question about variable name conflicts. I felt very interesting. By the way, I also reviewed some of the pre-resolution knowledge. If there is something wrong, I forgot my predecessor's guidance. The question is as follows:
Var a = 100; function a () {console. log (a) ;}a ();
After the code is executed, an error is returned: a is not a function.
Why is this error reported? This involves pre-parsing functions and variables:
1) function declaration will be set to the top
2) The variable Declaration will also be set to the top
3) function declaration is more advanced than variable Declaration: (the function is above the variable)
4) variables and value assignment statements are written together. During parsing by the js engine, the variables are split into two parts: Declaration and value assignment. The declaration is set to the top, and the value assignment is kept in the original position.
5) declared variables are not repeated.
The above code is equivalent:
Var a = function () {console. log (a);} var a = 100; ();
It is equivalent to re-assigning a value to a, so an error is reported.
The above discussion about variable names and function names in js is all the content shared by the editor. I hope to give you a reference and support for the help house.