js_立即执行函数是函数表达式

        function foo() {
            var a = 7;
            console.log(a);//7
            console.log(b);//b is not defined
            (function b() {
                a = 77;
            })();
            console.log(a);//77
        }
        foo();
        var c=function d(){
            console.log('this is d');
        }()//this is d

由上代码可见:立即执行函数不会有函数声明,当执行流执行到当前代码时才会对函数进行创建和调用。
当函数foo被调用,创建执行环境,对代码进行预处理时,立即执行函数不会有任何处理,甚至不会对它进行变量声明的提升。

posted @ 2020-07-12 13:41  Syinho  阅读(208)  评论(0编辑  收藏  举报