开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜