js 调用函数的方法

第一种:

function add(a,b){

        return a+b;

}

res=add(1,1);

console.log(res);

第二种:

let res=function add(a,b){

        return a+b;

}

console.log(res(2,2));

第三种 是比较特殊的:

function add(a,b){

        return a+b;

}(1,2)

console.log(res);

第四种  是立即调用的 函数前加符号: ! ~ 都是立即调用:

(function add(a,b){

        return a+b;

}(1,2))

猜你喜欢

转载自blog.csdn.net/qq1278169704/article/details/130516894