[英]Global Variable Scope Not recognized in Node.js console
So in a browser (chrome), if I run this code in the js console, the function call foo(); 因此,在浏览器(chrome)中,如果我在js控制台中运行此代码,则该函数将调用foo(); prints to the console the number 2. But if I run it in node.js, the function call foo() prints undefined .
将数字2打印到控制台。但是,如果我在node.js中运行它,则函数foo()会打印undefined 。 Why is this the case?
为什么会这样呢? Does node automatically run code in 'strict mode'?
节点是否以“严格模式”自动运行代码?
function foo() {
console.log(this.a);
}
var a = 2;
foo();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.