0

I know this is a base question but I wanted to ask which is the better place to put "use strict" if all the code is enclosed in the $(function() {} - eg: this statement is at the top of the file.

either:

$(function(){
   "use strict";
   // jQuery methods go here...

 });

or

"use strict";
$(function(){
   // jQuery methods go here...

 });  

I assume the second one is more througher as (if at the very top of the file) will cover off all the contents regardless of where placed.

Is this correct?

thx Adam

Adam
  • 19,932
  • 36
  • 124
  • 207
  • 1
    This similar question has some very good answers ~ http://stackoverflow.com/questions/4462478/jslint-is-suddenly-reporting-use-the-function-form-of-use-strict – Phil Sep 25 '14 at 03:41

1 Answers1

1

It depends on what part of your file you want to be strict. If you place it within the function, then only that function adheres to the strict principles. If you put it at the top of your file, then the entire file will use strict. If you are mixing deprecated methods mixed together with new ones then you may only want it within certain functions. It is a new feature of ECMAScript 5, but to answer your question, there is no better or worse. It just depends on what you're looking to do.

Russell Bevan
  • 334
  • 1
  • 13