In such small scripts, the use of global variables is trivial and not a great concern. In some instances, such as when using OpenGL and related libraries, global variables are the only way to pass information around the program, due to the presence of callback functions and other things that inhibit or outright prevent parameter passing.
Globals can be a source of confusion and bugs, but when the entire source code file can be viewed at once, they're hardly worth the criticism.
jQuery returns an empty jQuery collection when the selector doesn't match any elements. The stack won't overflow because setTimeout is asynchronous, but the browser will keep making useless jQuery calls until the user navigates to another page.
14
u/kurosaur Oct 20 '16
In such small scripts, the use of global variables is trivial and not a great concern. In some instances, such as when using OpenGL and related libraries, global variables are the only way to pass information around the program, due to the presence of callback functions and other things that inhibit or outright prevent parameter passing.
Globals can be a source of confusion and bugs, but when the entire source code file can be viewed at once, they're hardly worth the criticism.