I'm trying to validate my Google Analytics code using JSLint but I get a lot of error messages:
The code:
/*global document */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24389816-1']);
_gaq.push(['_trackPageview']);
(function () {
var s,
ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
}());
Error messages:
Problem at line 2 character 5: Unexpected dangling '_' in '_gaq'.
var _gaq = _gaq || [];
Problem at line 2 character 12: Unexpected dangling '_' in '_gaq'.
var _gaq = _gaq || [];
Problem at line 3 character 1: Unexpected dangling '_' in '_gaq'.
_gaq.push(['_setAccount', 'UA-24389816-1']);
Problem at line 4 character 1: Unexpected dangling '_' in '_gaq'.
_gaq.push(['_trackPageview']);
What's wrong? Thank you.
The jslint default settings do not allow an underscore at the beginning of variable names. This is because in other languages, it implies a private variable, something which JavaScript does not support.
To remove the warnings, you can add nomen: true
to the options of jslint. Otherwise, you will have to tolerate the warnings.
As far as I'm aware, Google does not offer a way to rename this variable at this time.
For JSLint or JSHint, set nomen: false
to ignore this warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With