JSHint ‘x’ is an implied global variable

| Javascript | jshint

I’ve started using JSHint to check my javascript. One error I encountered was:

Errors:
     85,5:'grammar' is not defined.
Warning:
     85,1: 'grammar' is an implied global variable.

This is saying that I’m using some variable that I’ve not declared in my javascript file. In most cases that would be a mistake, but in my case I was expecting it to be in the global scope included from another javascript file.

To make JSHint stop complaining about this, you can simply place the following at the top of your javascript document:

/*global grammar */

This will tell it that the variable is declared at a global scope. Check out one of my projects for example.