开发者

How do I return a value from a javascript function

开发者 https://www.devze.com 2022-12-31 23:14 出处:网络
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

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消