I'm learning how to change the context of the function in Javascript from this slide. Here the example given is perfectly understandable:
var object = {};
function fn(){
return this;
}
console.log( fn() == this) //true
console.log( fn.call(object) == object); //true
But when I try this in Node JS, the result is somewhat different. First statement results in false
and second equality is working as expected. So is there any difference in Global scope of Node JS and browser?
I know that browser has Global scope named window
, but what about Node JS? What is the difference between those scopes which leads to the above different behaviours?