JavaScript language basics 15 and javascript Language 15

Source: Internet
Author: User

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 _


Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.