Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSLint (Javascript Validator Website) - Error! Implied global:

I just tested my custom gallery script at JSLint.. and all errors where solved except for one. The implied global error.. Is this really an error? Can I ignore it or should I work on it to solve this error..?

Thank you for your responses!

alt text

Error:
Implied global:
<bunch of vars and other stuff i dont know>

What does this mean? BTW I use JQuery Library.. maybe thats the problem^^..

like image 689
Tomkay Avatar asked Jan 20 '23 19:01

Tomkay


2 Answers

if you use externally declared variables like in this case, put a 'global' statement at the top of your file, like this:

/*global $, document */

like image 151
Coen Avatar answered Jan 29 '23 09:01

Coen


JSLint documentation says:

Undefined Variables and Functions

JavaScript's biggest problem is its dependence on global variables, particularly implied global variables. If a variable is not explicitly declared (usually with the var statement), then JavaScript assumes that the variable was global. This can mask misspelled names and other problems.

JSLint expects that all variables and functions are declared before they are used or invoked. This allows it to detect implied global variables. It is also good practice because it makes programs easier to read.

Care for that error. Nearly every coding convention wants you not to use implied globals.

Variables can be declared using the var keyword.

like image 27
Karl von Moor Avatar answered Jan 29 '23 09:01

Karl von Moor