Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which ECMAScript 6 features imply strict mode?

In ECMAScript 5 (aka JavaScript,) I can trigger strict mode by adding "use strict" at the top of my function (or file, but this is discouraged.)

I understand that in ECMAScript 6, certain syntax features will turn on strict mode, especially class, and modules (however you do those.)

In the ECMAScript 6 world, what is the complete list of ways to trigger strict mode?

like image 566
Sean McMillan Avatar asked Mar 26 '15 16:03

Sean McMillan


People also ask

Is ES6 strict mode?

ES6 modules and classes are strict by default.

Which command will run script js with strict mode?

Strict mode for scripts To invoke strict mode for an entire script, put the exact statement "use strict"; (or 'use strict'; ) before any other statements.


1 Answers

The spec says:

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

The rest are just the known things from ES5, basically every global/eval/function code that begins with the "use strict"; directive. It does work within the new ES6 function kinds (arrow, generator, method syntax) as well.

like image 126
Bergi Avatar answered Sep 20 '22 15:09

Bergi