Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to use 'use strict' in IE 8/9

According the this http://caniuse.com/use-strict 'use strict' does not support in IE version 8/9.

My question is, Is it really safe to use 'use strict' in IE 8/9 or browsers that its not compatible with? Will it break my code?

like image 541
Shabith Avatar asked Aug 14 '13 04:08

Shabith


People also ask

Should I use strict mode?

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.

What are the effects of having use strict?

The "use strict" Directive It is not a statement, but a literal expression, ignored by earlier versions of JavaScript. The purpose of "use strict" is to indicate that the code should be executed in "strict mode". With strict mode, you can not, for example, use undeclared variables.

What is the benefit of using use strict `?

Benefits of using “use strict” It changes previously accepted "bad syntax" into real errors. As an example, mistyping a variable name creates a new global variable. When using strict mode, this will throw an error. It leads to making it impossible to accidentally create a global variable.

What are the advantages and disadvantages of using use strict?

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

The statement "use strict"; will should not cause problems with IE8/9 insofar as the browsers will run the code. (It was designed that way, to ensure that there are no problems with browsers that don't implement strict mode)

External source: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/

This means that you can turn strict mode on in your scripts – today – and it’ll have, at worst, no side effect in old browsers.

NOTE: as Jeremy pointed out in the comments, there are some expressions which are technically valid but will fail in IE8 (for example: var x = {}; x.break = true will not work in IE8 even though it will work in IE9).

like image 83
SheetJS Avatar answered Jan 03 '23 18:01

SheetJS