The problem of declaring a non-anonymous function in a function immediately

topic description

            var a=1;
            
            (function a(){
                console.log(1,a);
                a=2;
                console.log(2,a);
                delete a;
                console.log(3,a);
            })();
            console.log(4,a);

what exactly is the meaning of asking axi2? And why the output is the code of the a function itself?

Jun.06,2021

1, astat2; is relative to the first line of var axiom 1; and then, mainly demonstrates the scope of variables.
2, in the function expression (that is, the part of the function enclosed in parentheses), the role of an is the function itself, used for self-reference (such as recursion), is a "contaminated" variable name. The following assignments and deletions cannot operate on a because it is not a regular variable.


    a = 1
    // 
    var a = undefinded
    a = 1
    // 

so the an inside the closure is, of course, the function itself.

Menu