A function is a named group of JavaScript statements that you can declare once, near the top of your script, and call over and over again.
Declaring a function
function name ([parameter] [, parameter] [..., paramenter]){
statements
return value
}
statements
return value
}
Call a function
alert(“Total purchases come to ” + calculateTotal (10, 19.85))
Returning a value from a function
function calculateTotal (numberOrdered, itemPrice){
var totalPrice = (numberOrdered * itemPrice) + salesTax
return totalPrice
}
var totalPrice = (numberOrdered * itemPrice) + salesTax
return totalPrice
}
The call function above will not get the result without the returning value.



