You implicitly declare a variable several times using the function operator 'a () {};', which, as others have noted, raises this variable and behaves unexpectedly because the browser registers ads.
Behind the scenes, this statement creates an instance of the function object and assigns the result to the variable passed as the name of the function ( reference ), but this is done before explicit var declarations are executed, and thus overrides the implicit declaration. If you just do the following, it will work more intuitively:
var a = 1; a = function(){}; console.log(typeof a);
This is a better option than plural declaration of var in another answer from a logical point of view, because (although you can), it is not a good practice to declare a variable several times in any case.
To specifically answer the βwhyβ to this question: so that you can use these types of operators to define functions and use them in your explicit declarations, as in
var a = someFunction(); function someFunction(){ return 'someVal'; }
If function statements were not parsed and picked up first, this would not be possible.
jtrick
source share