How do I return a value from a javascript function
Say I have a function
function myFunction(myValue) {
// do something
}
How would I return a value from t开发者_JAVA百科his, say a string type after the method is executed?
Use the return
statement:
return "Hello";
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statements/return
Also, JavaScript is dynamically typed so you don't have to specify a type for the function, just return the variable.
function myFunction(myValue) {
// do something
// return to caller of function:
return myValue;
}
var result = myFunction(myValue);
精彩评论