Having too many global variables can cause problems in a program. When you declare global variables, they go to the global namespace, which allows the variables to be accessible from anywhere in the program. Variables remain in the global namespace until the program finishes, which means that the global namespace can fill very quickly. When we have too many global variables in the global namespace, or we reuse variables across different scopes, we have what’s known as scope pollution. In the following video, we will take a look at scope pollution so that we will know how to avoid it.
If you get stuck or need assistance, you can click the button below to connect with a tutor.
For additional questions or technical support, email email@example.com.