/

HTML / CSS / JavaScript Tutorial

JavaScript Statement: return

[this page | pdf | back links]

In JavaScript, the return statement stops execution of a function and returns a value from that function.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>

<script>
function multiply(a,b) {
  var c = a * b;
  return c;
}
var x = multiply(3,4);
document.getElementById("Example").innerHTML =
  'function multiply(a,b) {<br>' +
  '&nbsp;&nbsp;var c = a * b;<br>' +
  '&nbsp;&nbsp;return c;<br>' +
  '}<br>' +
  'var x = multiply(3,4);';
document.getElementById("Result").innerHTML = x;
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Reserved Words


Desktop view | Switch to Mobile