JS in the function key word is function, note the following:
function Add (NUM1, num2) {
return NUM1 + num2;
}
1, if the incoming var sum = Add (1, 6, 7); Only 1 and 6 are taken, and the last extra parameter is ignored.
2, if only add (1) is passed in, a nan is obtained because the function's formal parameter num2 is treated as undefined
3, the inside of the function has a arguments array, which is used to store the parameter list passed in, as the following is all the input parameters.
function Add (A, b) { var sum= 0; for (var i=0; i< arguments.length; i++) { sum+=arguments[i]; } return sum;} var sum = Add (1, 6, 7); Console.log (sum);
4,The parameter is a
value pass for the original type (that is, a copy is passed to it), and the argument is a reference pass for the object type (that is, the pointer is passed).
function Increment (a) { a = a + 1; return A;} var b = 4;var test = increment (b); Console.log (test); Console.log (b); var person = { age:10, name: ' Yanzi '};functi On addage (person) { Person.age = person.age + 1;} Addage (person); Console.log (person.age);
NetEase front-end micro-major, JavaScript programming Basics: Functions