Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something wrong if I use or not "use strict" mode in JS?

Tags:

javascript

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?

like image 647
Reacting Avatar asked Oct 28 '25 07:10

Reacting


1 Answers

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

like image 177
jdphenix Avatar answered Oct 31 '25 13:10

jdphenix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!