88

Jshint.com is giving the error:

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

Peter O.
  • 32,158
  • 14
  • 82
  • 96

4 Answers4

43

Add "use strict" at the top of your js file (at 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 about "use strict" in another question here on stackoverflow:

What does "use strict" do in JavaScript, and what is the reasoning behind it?

UPDATE.

There is something wrong with jshint.com, it requires you to put "use strict" inside each function, but it should be allowed to set it globally for each file.

jshint.com thinks this is wrong.

"use strict";    
function asd()
{
}

But there is nothing wrong with it...

It wants you to put "use strict" to each function:

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

Then it says:

Good job! JSHint hasn't found any problems with your code.

Community
  • 1
  • 1
Czarek Tomczak
  • 20,079
  • 5
  • 49
  • 56
  • Updated my answer again, hope this time it helps. – Czarek Tomczak Nov 12 '11 at 21:22
  • 21
    Actually, some (incorrect) scripts could try to simply concatenate multiple scripts, resulting in incorrect code(non-strict code being executed as strict). Making code strict per-function solves this problem. – luiscubal Nov 12 '11 at 22:13
  • 2
    It is not that uncommon for bundling tools to concatenate JS files and cause this problem. Really, you should wrap your whole file in an IIFE to avoid this and accidentally putting variables in the global scope. See @lenrok7 answer for how to do this. – Jeff Walker Code Ranger Apr 01 '14 at 02:20
35

JSHint maintainer here.

JSHint—the version used on the website—requires you to use function-level strict mode in your code. It is very easy to turn that off, you just need to uncheck "Warn when code is not in strict mode" checkbox:

jshint.com screenshot

Why don't we allow global strict mode as suggested by @Czarek? Because some of the JavaScript files used on your page might not me strict mode compatible and global strict mode will break that code. To use global strict mode, there is an option called globalstrict.

Hope that helps!

Anton Kovalyov
  • 2,808
  • 1
  • 22
  • 11
  • 1
    I don't see that "globalstrict" option on the screenshot, is it hidden somewhere? Why not add another checkbox called "Allow global strict", just below "When code is not in strict mode", and make it default. I think that most people who use strict mode, do it for whole files, it is a little overkill to add such line to every function. – Czarek Tomczak Nov 13 '11 at 23:49
  • 1
    For the sake of website's simplicity. You can read about all options in the docs and set them using `/*jshint */` constructions. Basically, I don't want jshint.com front page to be intimidating with myriads of options. – Anton Kovalyov Nov 15 '11 at 00:59
  • Can you help me set this option globally?http://stackoverflow.com/questions/9770968/passing-options-to-jshint – ripper234 Mar 19 '12 at 13:23
11

I think its because jshint is trying to "protect" us against accidental assignment strict mode to entire file. And also it is good to wrap code with anonymous function, or use somekind of namespace.

e.g. both function in strict mode:

(function() {

   "use strict";

   function foo() {
        .....
   }

   function bar() {
        .....
   }
}());
Kornel Dylski
  • 1,233
  • 14
  • 17
5

JSlint requires your code to be in 'strict mode'

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

MikeD
  • 123
  • 4
  • Yes, you'll put it in just as `"use strict";` The way ECMAScript 5 interprets this is as a function. ECMAScript 3 simply ignores it. – MikeD Nov 12 '11 at 19:52
  • What is the new code that you are passing through JSlint? – MikeD Nov 12 '11 at 20:33
  • 2
    Wrap your code in: `(function(){ "use strict"; //rest of your code }());` – MikeD Nov 12 '11 at 20:52
  • I also highly suggest giving this a read: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ – MikeD Nov 12 '11 at 20:54
  • I'm not 100% if it's an issue with JSHint, but right now that's the only way to get around the error issue. – MikeD Nov 12 '11 at 22:02