Javascript function declaration and return value, javascript function

Source: Internet
Author: User

Javascript function declaration and return value, javascript function

<1>


<Html xmlns = "http://www.w3.org/1999/xhtml"> 


Functions that cannot be returned by javascript

The array can be returned because there is an error in your code and the object cannot be found. You can look for something else. I have made two examples to return.
<Script>
Function getNum (getid ){
Var obj_Result = new Object ();
Obj_Result.one = "0 ";
Obj_Result.two = "1 ";
Obj_Result.three = getid;
Return obj_Result;
}
Function alt (){
Var obj_Result = new Object ();
Obj_Result = getNum ("2 ");
Var nodei = obj_Result.one;
Var nodej = obj_Result.two;
Var nodek = obj_Result.three;
Alert (nodei + "|" + nodej + "|" + nodek );
}
</Script>
<Button onClick = "alt ()"> click me </button>
<Script>
Function getNum (getid ){
Var arr = new Array ();
Arr [0] = "0 ";
Arr [1] = "1 ";
Arr [2] = getid;
Return arr;
}
Function alt (){
Var arr = new Array ();
Arr = getNum ("2 ");
Var nodei = arr [0];
Var nodej = arr [1];
Var nodek = arr [2];
Alert (nodei + "|" + nodej + "|" + nodek );
}
</Script>
<Button onClick = "alt ()"> click I 1 </button>

What is the return value of javascript Functions? What are the functions?

A function is an event-driven or reusable code block that is executed when it is called.

Compile the script as a function to avoid executing the script when loading the page.

A function contains code that can only be executed when an event is activated or called.

You can call the script anywhere on the page (if the function is embedded with an external. js file, you can even call it from other pages ).

The following are related details:
Www.w3school.com.cn/js/js_functions.asp

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.