I read an answer that "use strict" helps in restricting access to global variables and throwing unnecessary exceptions. But I just happened to wonder, whether "use strict" is still popular in ES6? OR is there an alternate (better) way today to achieving its functionality?
Asked
Active
Viewed 1,680 times
2
-
Strict mode is very much relevant, and is set automatically within the environment of some new syntax features, like `class`. – Mar 30 '18 at 23:03
-
Is this behavior- "setting it automatically for some environments" new to Es6? or just has been carried forward from JS5? – Srishti Ganjoo Mar 30 '18 at 23:05
-
It's new to features like `class`, which was introduced in ES6. The code in your methods defined in a `class` execute in strict mode. – Mar 30 '18 at 23:09
-
ES6 modules are automatically strict, but native module support is still scarce. – Felix Kling Mar 31 '18 at 15:09
1 Answers
0
For the most part it does work the same and the "use strict" string is still required at the top of your code to enter strict mode, even if you are using ES6 features. For example, if the code will be executed by a browser, the browser will not evaluate code in strict mode unless you use that string at the top of your code.
The only two exceptions are ES6 modules which automatically use strict mode, and ES6 classes, where any code in the body of the class is executed in strict mode.
You can find more details here at the MDN docs about Strict Mode and the docs about Classes

Todd Chaffee
- 6,754
- 32
- 41