38

I have some third party javascript im working with, I added some jquery code into it the javascript file. But it seems to fail on the above code when validating using Jslint

'$' was used before it was defined.

I can see at the top of the javascript file it states:

/*global alert: false, console: false, jQuery: false */

Im relatively new to Javascript, and JQuery, so any help would be welcome.

user1555190
  • 2,803
  • 8
  • 47
  • 80

3 Answers3

77

Add these options to your comments:

/*jslint browser: true*/
/*global $, jQuery, alert*/
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
kernel
  • 3,654
  • 3
  • 25
  • 33
  • Documentation on this is here under the "Global Variables" section: http://www.jslint.com/lint.html – fraxture Apr 05 '15 at 13:45
  • 1
    Why is it like that? Why can't JSLint just know JQuery? – Jessica Oct 21 '15 at 01:52
  • 1
    Because there is a world without jQuery, for example on Node.js or on Java Rhino. You don't always want jQuery in your environments, otherwise it could be build into the VM :-P – kernel Oct 27 '15 at 10:59
18

If you want to use variables provided by other scripts, then you need to say so:

/*global $ */
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
2

For JSLint In Netbeans IDE go to:

Tools - Options - Miscellaneous - JSLint tab - Text area under "Predefined (, separated)":

  • add $;
  • add your other project global variables, separating with comma.

Now JQuery variable $ is considered defined everywhere in code.

Zon
  • 18,610
  • 7
  • 91
  • 99