我一直在学习面试,并开始深入研究JavaScript。想出了这个。
所以:
"use strict";
var x = 0;
var y = 0;
eval("x=3;y=11;"); //direct call to eval in global scope
console.log("x: " + x); // outputs 3
console.log("y: " + y); // outputs 11
可是:
"use strict";
var x = 0;
(0, eval)("x=3;y=11;"); //indirect call to eval in global scope
console.log("x: " + x); // outputs 0 because the strict mode won't allow the reassignment?
console.log("y: " + y); // outputs 11
我不知道/了解执行eval时x会发生什么。我知道严格的模式关闭任务没有问题。有人愿意向我解释这个吗?谢谢!