How JS defines a function
Method 1:
Function name (parameter) {
function Body}
function Singlefun (a) {
Alert ("I am a parameter of the way one defines a function passed in with a value of:" + a);
}
Singlefun (666);
Method 2:var Function name =new function ("parameter", "function")
var sum = new Function ("Num1,num2", "return num1+num2");
Function call
var result1 = sum (120,130,66);
alert (RESULT1);
Method 3:var Function name =function (parameter) {List of functions}
var funname = function (A, b) {
alert (a); Abc
alert (b); True
}
Function call
Funname ("abc", True);
Arguments can be used directly in the body of a function, and we do not need to define it; he can accept all parameter lists
function sum () {
var result = 0;
for (var i = 0; i < arguments.length; i++) {
var p = arguments[i];
Alert (typeof (P) + "value" +p);
if (typeof (P) = = "Number") {
result + = P;
}
}
return result;
}
var result = SUM (12,88, "100", 50);
Alert ("And as:" +result)
How JavaScript defines a function