Why do people say that global variables are bad
I have always heard that you should not use global variables, but I use them a lot and never encounter any issues. Why are global variables bad and what should I use instead of global variables?
const is the best, use it if you can
let is the best, if you want to use a variable, that changes.
var should be only used, when you need the global functionality.
Global variables are bad because if you made a library, and they used global variables, it will conflict with other variables too.
so unless you are making a library, global variables are not truly a bad thing, but it makes it hard for your code to be maintained as it is hard to find where it was defined.
By the way, this is a global variable:
global = 5; window.global = 5;