Functions

As with PHP, JavaScript functions are used to separate out sections of code that perform a particular task. To create a function, declare it in the manner shown in Example 13-5.

Example 13-5. A simple function declaration
<script>
function product(a, b)
{
    return a*b
}
</script>

This function takes the two parameters passed, multiplies them together, and returns the product.

Get Learning PHP, MySQL, JavaScript, and CSS, 2nd Edition 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.