(5 + 5) / 2 // Returns 5 (15 + 3) / 2 // Returns 9 (7 + 2) / 2 // Returns 4.5
A function definition consists of the function
keyword, followed by three things:
- The name of the function.
- A list of parameters to the function, enclosed in parentheses (
( )
). - The code to be run when this function is run, enclosed in curly braces (
{ }
).
function average (number 1, number 2) {
return (number 1+ number 2/2);
}
console.log("first!");
console.log("second!");