Would this enable “use strict” globally?

前端 未结 3 1608
温柔的废话
温柔的废话 2021-02-02 09:20

Similar, but not the same as, How to enable ECMAScript \"use strict\" globally?

I have bought JavaScript Patterns and it recommends enabling use strict. Adding it to the

3条回答
  •  生来不讨喜
    2021-02-02 09:37

    no, script tags are considered programs and are therefor code units. "use strict" should not carry over from one script tag to another.

    Each script tag is interpreted individually and actually have their own scope. This scope is not noticable since everything declared globally will end up on the global object, but it's there nontheless. The string "use strict" will be garbage collected at the end of the program/script tag as it has no pointer/reference.

提交回复
热议问题