JSHint (forked from JSLint ) is a popular lint checker that runs in JavaScript code. It does not execute or modify the code, but analyzes it and reports various potential errors or bad practices that it finds.
If you have 'use strict';
at the top of your JavaScript file, outside of any JavaScript features, it will enable strict mode for the entire file. By default, JSHint will report a warning if it sees this.
'use strict'; window.permissions = null; function initialize() { window.permissions = 0; }
Warnings 1: Use the function form of "use strict".
This is due to the fact that many people automatically merge their JavaScript files together before sending them to the user, and in cases where the top level is 'use strict;'
may cause errors. For example, if you have 'use strict';
at the top of main.js
, and it is concatenated with the lax controls.js
mode, strict mode will inadvertently also apply to the code from controls.js
, which could potentially change its behavior.
// This code is fine on its own, but will break if strict mode is applied. document.querySelector('.upgade').onclick = function() { window.permissions = 0777; }
If this can happen in your case, you should avoid 'use strict';
at the top level of your file. You could have the whole file execute a spontaneous execution function to avoid the side effects of concatenation.
(function() { 'use strict'; window.permissions = null; function initialize() { window.permissions = 0; } }());
However, if you are sure that you do not need to worry about concatenation and do not want to change your code, globalstrict
for JSHint will disable this warning. It is also possible to specify JSHint parameters using a .jshintrc
file or the --config
command line flag, but in many cases this is the “built-in configuration” you saw - using a comment in a file is the easiest.
/* jshint globalstrict: true */