Using Parameters Between Functions

You can use parameters to pass data from one function (the referring function) to another (the receiving function).

Here is a simple example of this in action:

<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!-- Cloaking device on!
function first()
{
var x = 3, y = 5;
doAdd(x, y);
}

function doAdd(x, y)
{
alert(x + y);
}
// Cloaking device off -->
</script>
</head>
<body onLoad="first()">

</body>
</html>

In this example, the referring function (first()) is passing x and y to the parameters in the receiving function (doAdd()), which performs the math and outputs the answer.

This might seem of dubious value to you now (why not do the math in the first function and not have the second ...

Get JavaScript™ 1.5 by Example 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.