Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which (javascript) environments support ECMAscript 5 strict mode? (aka "use strict")

ECMAScript 5 is in its final draft as I write this; It is due to include a strict mode which will prevent you from assigning to the global object, using eval, and other restrictions. (John Resig's Article is a good introduction.)

This magical sanity-saving mode is triggered by including the string "use strict" at the top of your file (or function.) However, in older environments, "use strict" is a no-op. If you add "use strict" and don't test it in a strict environment, you could be leaving a time-bomb of not-really-strict code that will break when it really hits a strict environment.

Which environments actually respect "use strict"?

like image 773
Sean McMillan Avatar asked Sep 14 '09 20:09

Sean McMillan


People also ask

How strict mode is used in JavaScript?

Strict mode changes some previously-accepted mistakes into errors. JavaScript was designed to be easy for novice developers, and sometimes it gives operations which should be errors non-error semantics. Sometimes this fixes the immediate problem, but sometimes this creates worse problems in the future.

Does ES6 need use strict?

Strict Mode(“use strict”) helps identify common issues (or “bad” parts) and also helps with “securing” JavaScript. In ES5, the Strict Mode is optional but in ES6, it's needed for many ES6 features.

Is strict mode default in ES6?

ES6 modules and classes are strict by default.


1 Answers

Update:

See my compatibility table.

Original response:

None as of now.

Raphael Speyer was working on Mozilla implementation for Rhino during this summer, and afaik, their implementation is pretty close to completion.

I know (based on info from ES-discuss list) that Microsoft is planning to include some of ES5 features into upcoming versions of IE and they might very well be working on strict mode implementation right now (as you probably know, IE8 already includes some of ES5 features, like Object.defineProperty).

There's also Google's Caja project which somewhat emulates behavior of strict mode in some of its variations (Valija, Cajita, etc).

Crockford also recently added this option to JSLint, but I'm not sure if it actually triggers any additional validations (as per ES5-strict rules).

like image 168
kangax Avatar answered Sep 20 '22 17:09

kangax