1.3 ways to define a function:
// The 1.function statement will only be interpreted once, and the following will overwrite the previous one, with precedence resolved function test1 () { console.log (' test1 ');} Test1 (); // 2. The direct amount of the function will only be interpreted once, and the following will overwrite the previous, sequential parsing var test2=function() { console.log (' test2 ');} Test2 (); // 3. Each time you perform a dynamic new var test3=New Function ("A", "B", "Return a+b;"); // top-level scopes, sequential parsing console.log (TEST3);
2. Parameters of the function:
functionFun (a,b,c,d) {console.log (fun.length);//number of formal parameters //arguments object: can access the actual number of parameters, internal is an array, can only be used inside the function, often used for recursive operationConsole.log (arguments.length); Console.log (typeofarguments); Console.log (arguments); //Arguments.callee points to the function itself (fun) if(Arguments.callee.length = =arguments.length) { returnA +b; }Else{Console.log (' Pass parameter Error! '); }}fun ((a);
JavaScript function self-organizing