I have the following code:
function foo(){
console.log(this.a);
}
var a = 2;
foo();
The code above gives 2
when run in browser console. I run the same code in the terminal by doing node up-and-going.js
and got undefined
.
What am I missing?
PS: I'm new to JavaScript.