Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a reason not to use Strict mode in JavaScript?

Tags:

javascript

I have been wondering, without any specific context to this question, is there a reason not to use strict mode in JavaScript? I have hardly ever been working without it in JS and from all the reading I've done on the subject it seems purely beneficial as unsupported browsers just ignore the statement, but if that is the case, why don't browsers always use strict mode in the first place?

like image 364
Fenixp Avatar asked Jul 29 '13 08:07

Fenixp


People also ask

When would you not use strict mode?

If you have such an unrestrictedly typed code, that is used variables without declaring. One variable declared within some function/scope and used from somewhere else(it will be undeclared there) and you can't rewrite/change them, then you should not go for "use strict;" mode because it will break the code.

Should I use strict mode in JavaScript?

First, all of your code absolutely should be run in strict mode. Core modern javascript functionality is changed (see . call() and apply()) or disfigured (silent Errors) by executing code outside of strict mode.

Is strict mode important?

Strict mode eliminates some JavaScript silent errors by changing them to throw errors. Strict mode fixes mistakes that make it difficult for JavaScript engines to perform optimizations: strict mode code can sometimes be made to run faster than identical code that's not strict mode.

What is use strict What are the advantages and disadvantages to using it?

What is "use strict"; ? what are the advantages and disadvantages to using it? If you put "use strict"; at the top of your code (or function), then the JS is evaluated in strict mode. Strict mode throws more errors and disables some features in an effort to make your code more robust, readable, and accurate.


1 Answers

I have been wondering, without any specific context to this question, is there a reason not to use strict mode in JavaScript?

That is rather subjective.

I have hardly ever been working without it in JS and from all the reading I've done on the subject it seems purely beneficial as unsupported browsers just ignore the statement, but if that is the case, why don't browsers always use strict mode in the first place?

Because if a page uses JavaScript that depends on features of non-strict mode, that code will break.

Strict mode is not 100% backwards compatible. That is why it is has to be turned on by the person writing the JS.

like image 158
Quentin Avatar answered Sep 18 '22 03:09

Quentin