Page 209 - Web_Application_v2.0_C12_Fb
P. 209
<H2>JavaScript Functions</H2>
<P>This code calls a function which multiplies two numbers</P>
<SCRIPT>
function myFunction(p1, p2) //Function definition
{
document.write("The product is "+(p1*p2)); //Function body
}
myFunction(4, 3); //Function call
</SCRIPT>
</BODY>
</HTML>
Output:
The return Statement
Frequently, functions calculate a return value. The caller receives the return value. If a statement called the
function, JavaScript control will return to run the statements that follow after the function invocation. A return
statement in JavaScript causes the function to terminate.
The syntax to use the return statement in JavaScript is as follows:
function functionName(parameters){
//code block
return value;
}
Example 19: To demonstrate the use of return statement
Notes
<!DOCTYPE HTML>
<HTML>
Whenever we have a return statement
<HEAD> in a function, we must either store the
<TITLE>Return Statement</TITLE> result in a variable and output it or call
the function inside an output statement.
</HEAD>
Otherwise we will not get any output.
<BODY>
<H2>JavaScript Functions</H2>
<P>Function to convert temperature from Fahrenheit to Celsius</P>
<SCRIPT>
function Convert_to_Celsius(f) {
JavaScript Part 2 207

