admin管理员组文章数量:1291532
Say I have a function
function myFunction(myValue) {
// do something
}
How would I return a value from this, say a string type after the method is executed?
Say I have a function
function myFunction(myValue) {
// do something
}
How would I return a value from this, say a string type after the method is executed?
Share edited May 20, 2010 at 13:45 BalusC 1.1m376 gold badges3.6k silver badges3.6k bronze badges asked May 20, 2010 at 13:28 Calibre2010Calibre2010 3,8599 gold badges26 silver badges35 bronze badges 3- 1 w3schools./js/js_functions.asp – karim79 Commented May 20, 2010 at 13:30
- 7 That isn't a jQuery function. – user113716 Commented May 20, 2010 at 13:31
- 1 Since Javascript isn't strictly typed, while you can easily return a string as shown below, you aren't going to have a strict return type from your method, etc. – justkt Commented May 20, 2010 at 13:43
2 Answers
Reset to default 12Use the return
statement:
return "Hello";
https://developer.mozilla/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);
本文标签: How do I return a value from a javascript functionStack Overflow
版权声明:本文标题:How do I return a value from a javascript function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741533516a2383896.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论