A JavaScript function is a block of code designed to perform a particular task.
- The name of the function.
- A list of parameters to the function, enclosed in parentheses and separated by commas.
- The JavaScript statements that define the function, enclosed in curly brackets, {...}.
The code inside the function will execute when "something" invokes (calls) the function:
- When an event occurs (when a user clicks a button)
- When it is invoked (called) from JavaScript code
- Automatically (self invoked)
Calling the function actually performs the specified actions with the indicated parameters. For example, if you define the function square, you could call it as follows: square(5);