return

JavaScript 1.0+, JScript 1.0+ Nav2+, NES2+, IE 3+, Opera3+ Syntax

return

Description

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

Example

Listing 6.227 shows an example of using the return statement to return the value of the processing from the function.

Listing 6.227 Example of return
<html>
<body>

<script language="JavaScript">
<!–– Hide

function getValue(){
     var myValue = 4*3;
     return myValue;
}

function fill(){
     var x = getValue();
     document.form1.tmp.value = x;
}
// End Hide ––>
</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>
							
						

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.