A js function
function test(aa){window.alert("You typed"+aa);}Method 1: Call directly
test("dddd");
Method 2: Assign function to variable
var abc=test;
abc('China');//Call functions with variables
Notice:
When we write this form, var abc=test("dddd"); cannot call functions through the variable abc.
This way of writing when the test has a return value, it will assign the return value to abc. When there is no return value, the value of abc is undefined.
Special emphasis is placed on js that naturally supports variable parameters
//Writing a function that can accept as many numbers as possible and calculate their sum //Cannot be overloaded, abc2 function name cannot be repeated function abc2(n1){// You can ignore the parameter n1// There is an argument in js that can access all passed values. //window.alert(arguments.length);//traverse all parameters for(var i=0;i<arguments.length;i++){window.alert(arguments[i]);}}