Not recommended to use "use strict" in ES6?

JavascriptEcmascript 6StrictEs6 Modules

Javascript Problem Overview


I'm not familiar with ECMAScript 6 yet. I've just cloned the React Starter Kit repo, which uses ES6 for application code. I was surprised to see that the linter is configured to forbid occurences of the use strict directive, which I thought was recommended in pre-ES6 JavaScript. So what's the point?

Javascript Solutions


Solution 1 - Javascript

ES6 modules are always in strict mode. To quote the relevant part of the spec:

> ## 10.2.1 Strict Mode Code

> An ECMAScript Script syntactic unit may be processed using either unrestricted or strict mode syntax and semantics. Code is interpreted as strict mode code in the following situations: >

  • Global code is strict mode code if it begins with a Directive Prologue that contains a Use Strict Directive (see 14.1.1).

  • Module code is always strict mode code.

  • All parts of a ClassDeclaration or a ClassExpression are strict mode code.

  • Eval code is strict mode code if it begins with a Directive Prologue that contains a Use Strict Directive or if the call to eval is a direct eval (see 12.3.4.1) that is contained in strict mode code.

  • Function code is strict mode code if the associated FunctionDeclaration, FunctionExpression, GeneratorDeclaration, GeneratorExpression, MethodDefinition, or ArrowFunction is contained in strict mode code or if the code that produces the value of the function’s [[ECMAScriptCode]] internal slot begins with a Directive Prologue that contains a Use Strict Directive.

  • Function code that is supplied as the arguments to the built-in Function and Generator constructors is strict mode code if the last argument is a String that when processed is a FunctionBody that begins with a Directive Prologue that contains a Use Strict Directive.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMidiparseView Question on Stackoverflow
Solution 1 - JavascriptKit SundeView Answer on Stackoverflow