Returning values

Recall from last lesson's break.htm example that the prompt() method asks the user for input, and then either returns the input string, or null if the cancel button is pressed. User-defined functions can return values as well. To return a value from a function, use the 'return' keyword, followed by the value to be returned. The example on the previous page assigned a value to the variable, cubedNumber, and then used the following syntax to return that value to the calling program:

return cubedNumber;