Advanced Web Programming - Chapter 3
Advanced Web Programming - Chapter 3
Chapter 3: Functions
What is the Function?
To understand a function, lets discuss the following example:
As studied at school, distance is calculated by multiplying the speed by time.
In the example:
When the showDistance function gets called, the 10 corresponds to the speed argument, and the 5
corresponds to the distance argument. That mapping is entirely based on order.
A Simple Function
• Once the values you pass in as arguments reach your function, the names you specified for the arguments
are treated just like variable names
• The names of the arguments are treated as variable names.
• You can use these variable names to easily reference the values stored by the arguments inside your
function
Creating a Function That Takes
Arguments
• Once the values you pass in as arguments reach your function, the names you specified for the arguments
are treated just like variable names
• The names of the arguments are treated as variable names.
• You can use these variable names to easily reference the values stored by the arguments inside your
function
• You specify your arguments to the function as part of the function call: