This article mainly introduces two common methods for calling functions in js. If you need them, refer to the next js function.
Function test (aa) {window. alert ("You entered" + aa );}
Method 1: directly call
Test ("dddd ");
Method 2: assign a value to a variable
Var abc = test;
Abc ('China'); // call a function using variables
Note:
When we write this form, var abc = test ("dddd"); the function cannot be called through the abc variable.
In this way, when test has a return value, it will assign the return value to abc. When there is no return value, the value of abc is undefine.
In particular, JavaScript naturally supports variable parameters.
// Write a function that can accept any number and calculate their sum // It cannot be overloaded. The abc2 function name cannot be repeated function abc2 (n1) {// you can ignore the n1 parameter // There is an arguments in js that can access all input values. // Window. alert (arguments. length); // traverse all parameters for (var I = 0; I