在严格模式下间接调用 eval。 x会发生什么?

Indirect call to eval in strict mode. What happens to x?

我一直在为求职面试而学习,并开始深入研究 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

我不知道 know/understand 执行 eval 时 x 会发生什么。我知道在关闭严格模式的情况下,分配没有问题。有人愿意给我解释一下吗?谢谢!

这似乎是 Node.js 处理变量的方式(它们不默认为全局变量)。对 eval 的间接调用正在分配给全局对象。

"use strict";

var x = 0;

(0,eval)("x=3;y=11;");
x++;
console.log("x: " + x); // outputs 1
console.log("global x: " + global.x);  // outputs 3
console.log("y: " + y); // outputs 11