Fork me on GitHub

JSLint Error Explanations

JSLint will hurt your feelings. It's time to make them better!

Unnecessary use strict

When do I get this error?

JSLint will throw the "Unnecessary use strict" error when it encounters an occurence of the "use strict" directive in code that is already running in strict mode. In the following example we have a "use strict" directive in the global scope, and another in the function:

Why do I get this error?

This error is raised to highlight a completely pointless piece of code. The "use strict" directive applies to the scope in which it appears, and any descendant execution contexts. Here's what the ECMAScript 5 specification tells us about strict mode and functions (section §10.1.1):

Function code that is part of a FunctionDeclaration, FunctionExpression, or accessor PropertyAssignment is strict function code if its FunctionDeclaration, FunctionExpression, or PropertyAssignment is contained in strict mode code or if the function code begins with a Directive Prologue that contains a Use Strict Directive.

If JSLint throws this error at you, you can safely remove the highlighted instances of the "use strict" directive.

James Allardice

This article was written by James Allardice, an enthusiastic young JavaScript developer at Global Personals (we're looking for developers so please apply). He is passionate about writing clean, maintainable JavaScript and uses JSHint every day to help achieve this.

You can follow him on Twitter, fork him on GitHub and find him on Google+.

Proceeds generated by this site are donated to help advance other open source projects

comments powered by Disqus