JSLint's issue with 'window' as a global variable

Bjorn picture Bjorn · Sep 10, 2009 · Viewed 39k times · Source

So I'm using JSLint to try and detect errors. I turn some options off I don't like, but I don't see any way to enable being able to use the window global variable. Well, there is the Yahoo Widget option, but that's overkill.

What's the deal with using 'window', why would JSLint say that is causing errors?

Answer

Matt Clarkson picture Matt Clarkson · Sep 12, 2011
/*jslint browser: true*/

Was the correct solution to this. As of 2017-07-07, you have to set the global directive manually. From the JSLint documentation:

The /*global*/ directive is used to specify a set of globals (usually functions and objects containing functions) that are available to this file. This was commonly used in browsers to link source files together before ES6 modules appeared. Use of global variables is strongly discouraged, but unfortunately web browsers require their use. The /*global*/ directive can only be used when the Assume a browser option is selected.

So you will need to use:

/*jslint browser */
/*global window */