立即执行函数

写法

 (function(){}());//官方写法
 (function(){})();//第二种写法

获取返回值

         var num =  (function(a,b){//通过声明变量来接受返回值
            // console.log(a + b);
            return a + b;
        }(1,2))
        console.log(num);

函数声明和表达式的区别

       只有表达式才能被执行
        function test(){//函数声明,不能自调用

        }
        test();//表达式

        var demo = function(){//表达式
            console.log("2345");
        }();
posted @ 2020-11-11 10:41  残酷^现实  阅读(56)  评论(0编辑  收藏  举报