Summary

Completed

In this module, you explored how to create functions in JavaScript. A function is a great abstraction to use when you need to carry out the same task multiple times and want to avoid duplicating your code. You also learned the difference between a function and a method. These two types are both functions, but a function is free floating and a method sits on an object.

You then explored parameters and variables as important elements that allow functions to work with data.

Next, you learned about return variables. A return value is data leaving the function. Any invoker of a function can use the return value by assigning it to a variable.

Finally, you learned about anonymous functions. An anonymous function doesn't have a name, but it's a function that can be passed. It's commonly used in a context where a task needs to be performed that is asynchronous and will finish sometime in the future. Examples might be a timeout or fetching data across the network. After the task finishes, the anonymous function is invoked.