This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 6: Function scope

Summary

face Josiah Wang

What we have discussed in this chapter is quite advanced, so it is fine if you do not understand it. You can come back again later once you have more programming experience.

The main takeaway is that you should try to always keep all your variables inside the functions local, at least for now.

Keep each function independent of each other, and pass in any required variables as input arguments when calling the functions, and return the output. Avoid using variables directly from outside the local scope. And definitely avoid modifying any variables that are not in the local scope. This will avoid any unintended side-effects that will make it hard to debug your code. This is generally the safest way to code, especially if you are a beginner.