严格模式是否与单个 JavaScript 文件隔离?

Is Strict Mode isolated to individual JavaScript files?

当在 HTML 页面中包含的 JavaScript 文件的开头包含 'use strict'; 时,任何后续包含的文件或 JS 是否遵守在中建立的严格模式规则第一个文件?或者将严格模式隔离到第一个文件?

示例:

<script src="/path/to/file_using_use_strict.js"></script>
<script src="/path/to/file_omitting_use_strict.js"></script>
<script>
  console.log('Hello! Am I strict?');
</script>

我检查了 MDN documentation,但找不到概述这种特定情况的示例。谢谢!

来自Strict mode MDN web docs

Strict mode applies to entire scripts or to individual functions.

所以你的问题的答案是肯定的,严格模式只适用于你调用它的脚本或函数。