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?
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?
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).
myObject.break = true
works in strict mode, fails outside of it. –
Envoi var x = {}; x.break = true
works in IE9 (just tested it out in f12). Do you have access to IE9 and can you verify? –
Gunplay x["break"]
works. I wonder if that's due to some inconsistency between ES3 and ES5. Regardless, you are technically correct –
Gunplay x["break"]
works in ES3, but ES3 doesn't let you use dot notation if the property name is a keyword. Silly carryover that ES5 got rid of. It is an edge case that few people realize, but it has bitten me more than once working on various teams. I figure that some ES5 engines don't bother checking that rule in strict/non-strict mode. –
Envoi myObject.break = true
is only a SyntaxError in ES3-based engines/browsers (IE 8 and older). ES5 in general allows it, whether or not strict mode is used. Reserved words are only disallowed in ES5 when an Identifier is expected, while dot notation expects an IdentifierName. –
Telson Yeah, it should be fine.
use
directives are meant to be backwards-compatible. Browsers that don't support them will just see a String
literal that isn't referenced further. So, they'll pass over it and move on.
Though, you'll still want to be sure that you test your code both with and without it enabled.
© 2022 - 2024 — McMap. All rights reserved.