- Function: the code repeat cook package, can be directly invoked when needed
- The action function: code reuse
- Function need to define before you can use
- Function name: hump to follow nomenclature
- Once the function of the same name, the function will cover the front of the back
- Ctrl + left mouse button ----> Go To Definition
- A function is a function best
Function parameters:
- When the function definition, after the function name in parentheses is the variable parameters, the purpose is to function in the time of the call, the user-entered the value of the operation
- At this time behind the function definition parentheses variables called parameters; wrote two variables, there are two parameters,
- When a function call, follow the prompts way to assign values to variables ---> called by value, this value is passed to the variable (parameter)
- Parameter: function variable in time parenthesis defined in the parameter called
- Arguments: function called when the value passed in parentheses is called the argument, the argument can be a variable may be a value
// function definition function consoleSum (X, Y) { var SUM = X + Y; // Calculation ---- function and the console.log (SUM); // output and a second function --- } // Function call var num1 = the parseInt (prompt ( "enter first number" )); var num2 = the parseInt (prompt ( "enter the second number" )); consoleSum (num1, num2);
Function's return value:
- set: Set
- get: Obtains
- Return value: return keywords have internal functions, and the content in the back keywords, the content is returned
- When the function is called, it requires the return value, then the receiver on the definition of variables, you can
function GetSum (X, Y) { var SUM = X + Y; return SUM; // put and return } // function call var Result = GetSum (10, 20 is ); the console.log (Result +10);
- If there is a return function, the function returns the value there
- If a function does not return, then this function does not return value
- If there is no clear return value of a function, so when the call is received, the result is undefined
- (No explicit return value: function does not return, there is the function return, but later return nothing)
- Function does not return a value, but at the time of the call is received, then the result is undefined
- Variable declaration, there is no assignment, the result is undefined
- If a function has parameters, there are parameters of function
- If a function takes no arguments, no arguments
- The number and the number of arguments can be inconsistent parameter
- return the following code will not be implemented
// there are parameters, the function returns a value function F1 (X, Y) { return X + Y; } // have parameters, no return value of the function function F2 (X) { the console.log (X); } // No parameter, the function returns a value of function F3 () { return 100 ; } // no return value of the function parameter no function F4 () { the console.log ( "Sava Di" ); }