A function is a statement that can be run at any time, simply put, a function is a set of statements that completes a function, and it accepts 0 or more parameters.
the basic syntax for a function is as follows
Copy Code code as follows:
function functionname ([arg0,arg1,...... argn]) {
Statement
[Return[expression]]
}
Where the function is the keyword of the custom function, functionname is the name of the functions, and Arg represents a list of various parameters passed to the function, separated by commas. The argument can be empty.
Statement is a function of the province, can be a variety of legitimate blocks of code.
Reture expression is also optional for the return function's value expression. A simple example is shown below.
Copy Code code as follows:
function Sayname (yname) {
document.write ("Hello" + yname)
}
Sayname (112);
In addition, JavaScript does not execute Rerurn after it has been executed.
Copy Code code as follows:
<div id= "xxx" style= "Width:200px;height:100px;background-color:aquamarine" ></div>
<script type= "Text/javascript" >
function Cnumber (InNmuber1, InNumber2) {
return InNmuber1 + inNumber2
}
Irese = Cnumber (40,20);
document.getElementById ("xxx"). InnerHTML = Irese;
</script>
There may be more than one return in a function
Copy Code code as follows:
<div id= "xxx" style= "Width:200px;height:100px;background-color:aquamarine" ></div>
<script type= "Text/javascript" >
function Cnumber (InNmuber1, InNumber2) {
if (InNmuber1 >= inNumber2)
Return Innmuber1-innumber2
Else
Return Innumber2-innmuber1
}
Irese = Cnumber (10,20);
document.getElementById ("xxx"). InnerHTML = Irese;
</script>
This is the entire content of this article, the small partners whether the definition and invoke JavaScript have a new understanding of it, I hope this article can help