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