The return Statement

One statement you didn't look at in the previous chapter is the return statement. (Well, in fact there is one other—the with statement—but you'll come across that in the next chapter!)

The return statement was omitted from the previous chapter because it deals specifically with functions and at that time, you hadn't discovered functions. So, let's take a look at it now.

You've seen how parameters can be used to pass data from a referring function to a receiving function so that it can work on the data; well, there is a way to pass the result back. This is done with the return statement:

 <html> <head> <title>A Simple Page</title> <script language="JavaScript"> <!-- Cloaking device on! function calcAvg() { var inpNum1 = prompt("Enter ...

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.