3

I am working on a Gulp file and I just set JSHint, I see this option in the .jshintrc file:

"strict" : true

then I went to my files I put this at the very beginning:

'use strict';

angular.module('MyApp', ['ngRoute'])
  .config(function($locationProvider, $routeProvider) {. . .});

and I now I am getting a new error

public/app.js line 1 col 1 Use the function form of "use strict".

so I did:

angular.module('MyApp', ['ngRoute'])
  .config(function($locationProvider, $routeProvider) {

  'use strict';

   return { . . . }

});

and the error its gone.

So, what is the difference here and what is wrong if I don't use the strict mode?

Reacting
  • 5,543
  • 7
  • 35
  • 86
  • See [What does “use strict” do in JavaScript, and what is the reasoning behind it?](http://stackoverflow.com/q/1335851/1529630) and [JSLint is suddenly reporting: Use the function form of “use strict”](http://stackoverflow.com/q/4462478/1529630) – Oriol May 08 '16 at 23:25

1 Answers1

5

JSHint by default doesn't allow you to have 'use strict'; at a global scope when set to true, because it will interfere with Javascript libraries and legacy code that isn't designed for strict mode in mind.

Use

strict: 'global'

if you want to be able to do that.

or

strict: false

if you do not want to lint code to require strict mode.


strict option reference for JSHint

jdphenix
  • 15,022
  • 3
  • 41
  • 74
  • Oh, I see. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode This tells you how strict mode behaves – jdphenix May 08 '16 at 23:19