是否需要从JavaScript函数返回值?
JavaScript函数可以具有可选的return语句,即返回值是可选的。该语句应该是函数中的最后一条语句。
例如,您可以在一个函数中传递两个数字,然后可以期望该函数将它们的乘法返回给您的调用程序。
示例
请尝试以下示例。它定义了一个函数,该函数接受两个参数并将它们连接起来,然后在调用程序中返回结果。
<html>
<head>
<script type = "text/javascript">
function concatenate(first, last){
var full;
full = first + last;
return full;
}
function secondFunction(){
var result;
result = concatenate('John', 'Doe');
document.write (result );
}
</script>
</head>
<body>
<p>Click the following button to call the function</p>
<form>
<input type = "button" onclick = "secondFunction()" value = "Call Function">
</form>
<p>Use different parameters inside the function and then try...</p>
</body>
</html>热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短