Something in [] inside the function means dispensable.
Function
Custom functions
function declaration:
function name ([argument list]) {
function body;
[Return value];
}
(both the argument list and the return value are optional)
Call to function:
Call directly: function name ()
Event Invocation:
1, <input type= "button" value= "+" onclick= "f ()"/>
2, <p id= "a" ></p>
document.getElementById ("a"). Onclick=f;
function f () {
}
3, document.getElementById ("a"). Onclick=function () {} anonymous function
Parameters for the function:
Formal arguments (parameters): Defining the variables in parentheses when a function declaration
Actual arguments (arguments): Defining the variables in parentheses when a function is called
Formal parameters and argument passing:
Pass the actual argument to the formal parameter, the process of assigning a value to the formal parameters
eval (); parsing function
function return value
Return End Function and let the function have a value, in a function can have multiple return, but only the first return has effect
Return function value is undefined
return "Sadas"; function value is "Sadas"
return a+b; function value is the result of an expression
return true/false; function value is True/false
Processing of function return values:
can be used as actual parameters
can also be used as a value of a variable
can be directly output
Can be used in another function
Scope of variable:
Global variables: Variables declared in the function body with VAR or var declaration in the function body are called global variables
Scope of global variables: is the current document
Life cycle of global variables: destroy after browser shutdown
Local variables: Variables declared in the function body with VAR are local variables
Scope of local variable: is the current function
The life cycle of a local variable: The current function is destroyed when it is finished.
Overload of function: There is no overload in the JS language (function is called method)
Overload:
The method name (function name) is the same, the argument list is different or the number of parameters is different or the data type of the parameter is different
function f (a,b) {
return a+b;
}
function f (a,b,c) {
return a+b+c;
}
In other functions
F (10,20)
F (10,20,309)
F (10,20,213)
Call a different function based on the number of subsequent arguments
And in JS inside
Regardless of the number of arguments behind it is the latter function that is called by several
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.