Changes

Understanding JavaScript Functions

4 bytes added, 13:37, 20 June 2007
Returning a Value from a Function
The above example passes 10 and 20 through to the addValues function. The addValues function adds these two values together and returns the result. The assignment operator assigns the result to the variable ''result'' which is then used to construct a string which, in turn, is written to the HTML page.
The function call can be made in many different places. For example, we do not need to assign the result to a variable, we can use it directly as an argument to the document.write call:
It is important to note that a function can return one, and only one value.