Return value from a function : Function Return « Function « JavaScript Tutorial






<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!--
function calcAvg()
{
    var inpNum1 = 1;
    var inpNum2 = 2;
    var inpNum3 = 3;
    var inpNum4 = 4;
    numAvg = doCalcAvg(inpNum1, inpNum2, inpNum3, inpNum4);
    document.write("The average of the four numbers you entered is: " + numAvg);
}

function doCalcAvg(inpNum1, inpNum2, inpNum3, inpNum4)
{
    var ans;
    ans = (Number(inpNum1) + Number(inpNum2) + Number(inpNum3) + Number(inpNum4)) / 4;
    return (ans);
}
//  -->
</script>
</head>
<body onLoad="calcAvg();">
</body>
</html>








7.7.Function Return
7.7.1.return
7.7.2.Returning Values
7.7.3.Return value from a function
7.7.4.Return boolean value from function
7.7.5.Return an array from a function