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.
-6
u/witchwind Oct 19 '16
For those of you who haven't realized why this is bad code yet, it passes strings into setTimeout() and defines global variables.