JavaScript language basics 15 and javascript Language 15
Define your own functions in JavaScript. functions are program units that execute specific functions. We have learned the built-in functions of JavaScript, such as parseInt () and parseFloat.
Now let's create our own defined functions:
<HTML><HEAD><TITLE>Hello World</TITLE></HEAD><BODY BGCOLOR="WHITE"><SCRIPT Language="JavaScript" TYPE="text/javascript">function agePrint(value){document.write("(agePrint)age:"+value+"<br>");return value;}var age=agePrint(20);document.write("age:"+age+"<br>");</SCRIPT></BODY></HTML>
The preceding agePrint () is a custom function name (the function name cannot be a reserved word in JavaScript) and is located after the function keyword. The function parameters should be placed in parentheses after the function name. Use the following age = agePrint (20); call the custom function, pass the parameter 20, and assign the value returned by return to age.
Let's take a look at the scope of the variable. The scope of the variable is the valid scope of the variable. The scope of the variable declared outside the function is all the script code on the page, you can access either the script code in the function or the script code outside the function.
The variables defined in the function are local variables, and the scope is limited to this function block. We can define the same variable name in each function, you can also define a variable name out of a function exactly the same as that defined in the function, but only once (the same variable name is not recommended in actual code ).
Reprinted please indicate the source: http://blog.csdn.net/hai_qing_xu_kong/article/details/41413431 sentiment control _