JSHint - Use Strict - Strange Behavior

Does this work? When I enable, I get all kinds of errors telling me expected "use strict;"; statement, no matter how many I put in or where I put them. Also, if I put a "use strict;"; the top of my file, I get "Expression or statement is not assigned or called" error (even without JSHint turned on.)

Capture.PNG

3 comments
Comment actions Permalink

Hi Keith,

> When I enable, I get all kinds of errors telling me expected "use  strict;"; statement, no matter how many I put in or where I put them

please, try "use strict";, not "use strict;"; (note the extra ';' inside the statement)
If you don't like using the "use strict" statement, you can disable the corresponding JSHint inspection - just uncheck the 'When code is not in strict mode' checkbox in JSHint settings

>Also, if I put a "use strict;"; the top of my file, I get "Expression or statement is not assigned or called" error

make sure to set the JavaScript language version to 'ECMAScript 5.1' in Settings/JavaScript - this is ECMAScript 5 feature


Best regards,
Lena

1
Comment actions Permalink

lena_spb wrote:

Hi Keith,

> When I enable, I get all kinds of errors telling me expected "use  strict;"; statement, no matter how many I put in or where I put them

please, try "use strict";, not "use strict;"; (note the extra ';' inside the statement)
If you don't like using the "use strict" statement, you can disable the corresponding JSHint inspection - just uncheck the 'When code is not in strict mode' checkbox in JSHint settings

>Also, if I put a "use strict;"; the top of my file, I get "Expression or statement is not assigned or called" error

make sure to set the JavaScript language version to 'ECMAScript 5.1' in Settings/JavaScript - this is ECMAScript 5 feature


Best regards,
Lena

No, I am trying to use strict mode for the first time.

Already set to ECMAScript 5.1. When I do

"use strict";

I get a different error:
Capture.JPG

0
Comment actions Permalink

It appears that by default now, JSLint & JSHint don't allow global use strict:

http://stackoverflow.com/questions/4462478/jslint-is-suddenly-reporting-use-the-function-form-of-use-strict

But it can be done:

/*jshint globalstrict: true*/

1

Please sign in to leave a comment.