I'm still learning JavaScript and when I tried to get an understanding of this
behavior, I've got a little confused. One thing that I understand that this
keyword is actually refer to where is the call-site of the function when it called. I was trying run the example code below:
function foo() {
console.log ( this.a );
}
var a = 2;
foo();
The expected result is 2. It did show 2
on Chrome's console but when I tried to run it from NodeJS, result result would be undefined
. my Node version is 6.10.1
Is the call-site will be different when the code run in Node compare to Browser's Console or is there anything that need my concern when I'm running code on nodeJS especially when using this
keyword?