The third chapter of the advanced programming of JavaScript mainly describes the basic concept of the language, the content is many and shallow, through the mind map can help us to clarify the context.
The JS function uses the function keyword to declare, here is a simple example:
1 function Sayhi (name, message) {2 alert ("Hello," +name + message); 3 }
The return statement can be used in a function to specify the returned value, and if only "return;" The function will return undefined after it has stopped executing;
The function defined has 2 parameters, so when calling this function, it is not necessary to pass two parameters: 1, 2, 3 ... Or not pass it all-because the ECMAScript parameter is internally represented by an array, and a named parameter that does not pass the value is automatically given the value of undefined; in the body of the function, the array of arguments can be accessed by arguments objects:
1 function Doadd (NUM1, num2) {2 if (Arguments.length = = 1) {3 alert (NUM1 +); 4 } Else if (Arguments.length = = 2) {5 alert (arguments[0] +); 6 }7 }
With regard to the behavior of arguments, its value is always synchronized with the corresponding named parameter, but this does not mean that the two values will access the same space, their memory space is independent, but their values will be synchronized:
1 function Doadd (NUM1, num2) {2 // overriding the second parameter is ten 3 // the value of the num2 is ten 4 }
ECMAScript defined functions cannot be overloaded because they do not have function signatures (function signatures: function declaration information, including: parameters, return values, calling conventions, etc.).
The third chapter of the advanced programming of JavaScript