Reputation: 23
So in a browser (chrome), if I run this code in the js console, the function call foo(); prints to the console the number 2. But if I run it in node.js, the function call foo() prints undefined. Why is this the case? Does node automatically run code in 'strict mode'?
function foo() {
console.log(this.a);
}
var a = 2;
foo();
Upvotes: 2
Views: 1032