return : Function Return « Function « JavaScript Tutorial






The return keyword will exit the existing function and return a value.

<html>
    <body>
    <script language="JavaScript">
    <!--
    function getValue(){
         var myValue = 4*3;
         return myValue;
    }
    function fill(){
         var x = getValue();
         document.form1.tmp.value = x;
    }
    -->
    </script>
    <form name="form1">
    Value: <input type="text" Name="tmp" Size=5>
    <br>
    <br>
    <input type="button" name="get" value="Get Returned Value" onClick='fill()'>
    <br>
    <br>
    </form>
    </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