JavaScript Functions

A JavaScript function is a block of code designed to perform a particular task.It is executed when "something" invokes it (calls it). This example calls a function which performs a calculation, and returns the result:

HTML file: Displayed by browser:
<body>
<p>The result for this function is:</p>
<p id="demo"></p>
<script>
function myFunction(a, b) {
    return a * b;
}
   document.getElementById("demo").innerHTML = myFunction (4, 3);
</script>
</body>

The result for this function is:


BackTable of ContentsNext