The default setting here is easy to think is similar to PHP
function (v1,v2= "Test") {alert (v2);}
But this is not right, JS method, such as the need to pass parameters, even without the predefined (that is, no need to write the parameter name in the parentheses of the definition function), JS function has a storage parameter of the array arguments , all functions obtained parameters will be saved to the array by the compiler. As follows:
functionTestarg () {//Traverse 1 for(vari=0;i<arguments.length;i++) {alert ("Traverse 1:" +Arguments[i]); } //Traverse 2 for(varEleincharguments) {Alert ("Traverse 2:" +arguments[ele]);// Subscript}} testarg ("A", "B"); functionTestargno () {varARG =typeof(Arguments[0]) = = "undefined"? "No value passed": "Pass value is:" +arguments[0]; alert (ARG); } testargno (); Testargno ("A");
JS method parameter Default value setting