javascript tutorial - [Solved-5 Solutions] Jsl int is suddenly reporting use the function form of use strict - javascript - java script - javascript array



Problem:

Use the function form of “use strict”

Solution 1:

include the statement:

"use strict";
click below button to copy the code. By JavaScript tutorial team

at the beginning of most of my Javascript files.

Solution 2:

(function () {
   'use strict';
   // this function is strict...
}());

(function () {
   // but this function is sloppy...
}());
click below button to copy the code. By JavaScript tutorial team
  • Update: In case we don't want to wrap in immediate function (e.g. it is a node module), then we can disable the warning.
  • For JSLint (per Zhami):
/*jslint node: true */
click below button to copy the code. By JavaScript tutorial team

For JSHint:

/*jshint strict:false */
click below button to copy the code. By JavaScript tutorial team

Solution 3:

/*jslint node: true */
click below button to copy the code. By JavaScript tutorial team

Solution 4:

warning via

/*jshint globalstrict: true*/.
click below button to copy the code. By JavaScript tutorial team

Solution 5:

If we try it now, we will scan our Gruntfile… and get some errors:

$ grunt jshint

Running "jshint:all" (jshint) task
Linting Gruntfile.js...ERROR
[L1:C1] W097: Use the function form of "use strict".
'use strict';
Linting Gruntfile.js...ERROR
[L3:C1] W117: 'module' is not defined.
module.exports = function (grunt) {

Warning: Task "jshint:all" failed. Use --force to continue.
click below button to copy the code. By JavaScript tutorial team

Both errors are because the Gruntfile is a Node program, and by default JSHint does not recognise or allow the use of module and the string version of use strict. We can set a JSHint rule that will accept our Node programs. Let’s edit our jshint task configuration and add an options key:

jshint: {
  options: {
    node: true
  },
}
click below button to copy the code. By JavaScript tutorial team

Related Searches to javascript tutorial - Jsl int is suddenly reporting use the function form of use strict