ecmascript-6 – About the relationship between "use strict" and ECMAScript6

Question: Question:

Will what happens only when "use strict" is set in ECMAScript5 continue in ECMAScript6?
-For example, when a function is called, will "the phenomenon that this becomes undefined in strict mode and becomes global this (window in the browser) in non-strict mode" continue?
-If you do not explicitly add "use strict" as usual, will it not be undefined in the non-strict mode?

Answer: Answer:

The Strict Mode distinction continues in ECMAScript 2015 (ES6) / ECMAScript 2016.
Existing behavior cannot be modified for backwards compatibility.

However, where there is no need to consider backward compatibility, it defaults to Strict Mode behavior.
In particular,

  • Inside the Class definition
  • Whole code loaded as Modules


Inside the Class definition

class A {
    foo() {
        console.log("ここは Strict Mode です");

console.log("ここは Strict Mode ではありません");

function foo() {
    "use strict";
    console.log("ここは Strict Mode です");

Whole code loaded as Modules

In the browser, if you load the JavaScript code as type="module" as follows, the code will be treated as a module.

<script type="module" src="foo.js"></script>

All code loaded as a module will be forced into Strict Mode.

See Also: See Also:

Scroll to Top