A.
在函数体的第一行写入指令序言
function doSomething() {
"use strict";
// ...
}
B.
在脚本最顶部启用严格模式(影响整个脚本中的函数)
"use strict";
function doSomething() { /* ... */ }
C.
以 ES Module 方式运行(模块默认严格模式)
浏览器:`<script type="module">...</script>`
Node.js:`"type":"module"` 或使用 `.mjs`
D.
在函数体内的非首行或注释中写入 "use strict"
function doSomething() {
// ...
// "use strict"; // 非指令序言,不生效
}