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 14-9.

Example 14-9. 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, and JavaScript 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.