Skip to content
Advertisement

How to avoid using global variables?

I use global variables but I’ve read that they aren’t a good practice or pythonic. I often use functions that give as a result many yes/no variables that I need to use in the main function. For example, how can I write the following code without using global variables?

JavaScript

Advertisement

Answer

One could ask what reasons you might have to structure your code like this, but assuming you have your reasons, you could just return the values from your secondary function:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement