Working with Functions
Here is an example of calling a JavaScript function:
Task
Run the above and the code from the previous lesson and experiment with the code to get used to it.
JavaScript Function Summary
Here is a summary of the JavaScript functions that were covered in this chapter:
- A function is a block of code that is executed when it is called.
- Functions are used to encapsulate code and make it reusable.
- The syntax for a JavaScript function is as follows:
function functionName(parameters) {
// code to be executed
}
- A function is called by using its name.
- The scope of a function determines where the function can be called.
- Parameters are values that are passed to a function when it is called.
- A function can return a value.