I'm currently face with a problem where I have two modules that I call that need to be able to modify the same variable.
I decided to create a global variable called global.APP_NAME = {} and store the variables that I need in that.
But I have been reading that it is bad practice to use global variables. Why is it?
I am only creating one variable, that should not collide with anything else because it is the name of my application.
Global variables are considered an anti-pattern in almost any programming language because they make it very hard to follow and debug code.
When you have two modules which share data, you should create an object with that data and explicitly pass it to each function which needs it (and only those which actually do).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With