That is so because , global scope in browser and nodejs are different. When you declare a var in browser , variable is attached to global scope and can be accessed by this operator. Where as it is not the case with nodejs.
So if you copy paste and run this code in browser it would work as expected.
0
solved JavaScript binding of global result is undefined [closed]