【发布时间】:2015-09-13 08:02:25
【问题描述】:
想知道下面 sn-p 或 -https://jsfiddle.net/uhznvphn/ 的幕后发生了什么 当全局 x=20 被注释掉时,它会出错,这很好! 但是当它被取消注释时,它会打印 10。它不应该出错,因为我们仍然处于严格模式并且尚未声明本地“x”变量。即使它没有出错,它不应该打印 20
x = 20; //Comment and uncomment to see diff results
function a() {
"use strict";
x = 10;
console.log(x);
}
a();
【问题讨论】:
标签: javascript strict