Why are global variables considered bad practice?

后端 未结 7 1640
野趣味
野趣味 2020-11-22 03:19

I keep seeing warnings not to use global variables in JavaScript, but it seems that the only reason people say that is because the clogs up the global namespace. I can imagi

7条回答
  •  面向向阳花
    2020-11-22 03:36

    The global variable which you have created might overwrite the existing window object properties. Because the global variables are accessing in global context i.e. window object.

提交回复
热议问题