Summary of Functions

Review what we have covered in this chapter.

We'll cover the following

Chapter summary

In this chapter, we saw that functions are a powerful tool we can use to organize and structure our code to make it more readable and reusable. We saw how functions have a name, and that name can be used to call them. Calling a function makes the code inside it execute. This is something we can do over and over again as often as we need to.

Sometimes, we want functions to produce a value as a result of its operations. In those cases, we can let the function return something. We can then use that value in the location where we called the function.

Then, we learned that we can also pass data into a function. This can be done using function arguments. The function receives these arguments in local variables called parameters.

With the introduction of functions, we also have the concept of variables being either global or local. We saw that global variables can be accessed from any location within the program and local variables can only be used within the function where they’re created.

Sometimes, things won’t go according to plan, and we’ll discover that our program either produces the wrong results or simply crashes.

Get hands-on with 1200+ tech skills courses.