return
関数からの戻り値を指定します。戻り値がない場合や関数から抜けたい場合には単純にreturnとだけ指定します。戻り値は数値や文字列だけでなく配列やオブジェクト、関数、プロパティやメソッドなどJavaScriptで扱えるものであれば何でも戻り値として指定することができます。
構文
return 戻り値
例文
<html>
<head>
<title>return</title>
</head>
<body>
<script type="text/javascript"><!--
function calc(a, b) {
var n = a + b;
return "加算結果は"+n+"です"
}
document.write(calc(3,5));
// --></script>
</body>
</html>
関連記事
- with
- while
- var
- try
- throw
- this
- switch
- new
- if
- function
- finally
- else
- do
- delete
- default
- continue
- const
- catch
- case
- break
- Comment / コメント / 注釈
スポンサーリンク





