Jshint.com requires "use strict." What does it mean?

Jshint.com reports an error:

Line 36: var signin_found; Missing "use strict" statement.

+56
javascript jshint
Nov 12 '11 at 19:34
source share
4 answers

Add "use strict" at the top of your js file (on line 1 of your .js file):

"use strict"; ... function initialize_page() { var signin_found; /*Used to determine which page is loaded / reloaded*/ signin_found=document.getElementById('signin_button'); if(signin_found) { 

More on "use strict" in another question here in stackoverflow:

What is "use strict" to do in JavaScript and what are the reasons for this?

UPDATE

There is something wrong with jshint.com, it requires you to "use strict" inside each function, but you need to allow it globally for each file.

jshint.com thinks this is wrong.

 "use strict"; function asd() { } 

But there is nothing wrong with that ...

He wants you to use "use strict" for each function:

 function asd() { "use strict"; } function blabla() { "use strict"; } 

Then he says:

Good job! JSHint did not find any problems with your code.

+34
Nov 12 '11 at 19:46
source share

Supporting JSHint here.

JSHint - the version used on the website - requires the use of strict mode at the function level in your code. This is very easy to disable, you just need to uncheck the box "Warn me when the code is not in strict mode":

jshint.com screenshot

Why don't we allow the global strict mode proposed by @Czarek? Since some of the JavaScript files used on your page may not conform to strict mode, global strict mode violates this code. To use global strict mode, there is a globalstrict option.

Hope this helps!

+31
Nov 12 2018-11-11T00:
source share

I think this is because jshint is trying to "protect" us from the random string assignment mode for the entire file. It is also useful to wrap the code with an anonymous function or use somekind namespaces.

eg. both work in strict mode:

 (function() { "use strict"; function foo() { ..... } function bar() { ..... } }()); 
+10
Jul 24 '13 at 13:20
source share

JSlint requires your code to be in strict mode

To do this, simply add "use strict"; to the beginning of your code.

+4
Nov 12 '11 at 19:37
source share



All Articles