Why Global Variables Shouldn’t Be Very Global

One of the biggest blunders a JS developer can do make while writing code is declaring unnecessary global variables. Global variables are extremely helpful for programmers, but if they are not used carefully, they can rob the speed and efficiency of any browser.

Short Note

There are mainly two types of variables that are used in JS: local and global. Local variables are defined and used within a function, whereas global variables are defined for the function window. In short, until the code doesn’t terminate, global variables will be present, lurking in the background.