A function is a statement that can be run at any time, simply by saying that a function is a set of statements that completes a function that accepts 0 or more parameters.
The basic syntax for a function is as follows
function function Name ([arg0,arg1,...... ArgN]) {statement[return[expression]]}
where function is the keyword of the custom functions, functionname is the function name, ARG represents the various parameter lists passed to the function, and the parameters are separated by commas. The parameter can be empty.
Statement is a function of the province, can be a variety of legitimate code blocks.
Reture expression is the value of the return function expression, which is also optional. A simple example is shown below.
function Sayname (yname) { document.write ("Hello" + yname) } sayname (112);
In addition, JavaScript does not execute after Rerurn.
<div id= "xxx" style= "width:200px;height:100px;background-color:aquamarine" ></div><script type= " Text/javascript "> function cnumber (InNmuber1, inNumber2) { return InNmuber1 + inNumber2 = cnumber (40,20); document.getElementById ("xxx"). InnerHTML = Irese; </script>
There may be multiple return in a function
<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 = cnumber (10,20); document.getElementById ("xxx"). InnerHTML = Irese; </script>
JavaScript Basic Series (vii) function (definition and allocation function)