javascript function analytic

A, javascript function definition

1, the function declaration format

    function test(){
        console.log("这是一段非常流皮的代码");
    }

2, function expression format

        //2.1命名函数表达式(表达式忽略它的名字)
        var test = function fun2(){
            document.write();
        }
        //2.2匿名函数表达式,常用
        var test2 = function (){
            document.write();
        }

Second, the function parameters

        //形参和实参的数目可以不匹配,实参给多少用多少
        function fun(arg1, arg2){
            if(arguments.length > fun.length){
                console.log("实参多于形参");
            }else{
                console.log("形参多于或者等于实参");
            }
            //遍历实参
            for(var index = 0; index < arguments.length; index++){
                console.log(arguments[index]);
            }
        }
        fun(1,"2",3);

Guess you like

Origin www.cnblogs.com/Bai-Bai/p/12112219.html