Doing further research:
this
in a module script refers to exports
within the module scope.
this
in the REPL refers to the global
object.
Looking at shambalambala answer. this
within an IIFE in Strict Mode is undefined and in Standard Mode it is the global object.
From: Why console.log(this) in node return empty object? by T.J. Crowder
Because NodeJS runs your code in a module, and this references the object it creates for your module's exports (which is also the exports property on the module variable it provides you). (As they don't really mention that in the module documentation, I suspect using it is probably not a great idea — use exports instead.)
But your code calling the IIFE calls it with this referring to the global object, because in loose (non-strict) mode, calling a normal function not through an object property calls it with this set to the global object. (In strict mode, this would be undefined there.)
Why does this
become undefined within the IIFE in Strict mode?
From: Why is "this" in an anonymous function undefined when using strict? by jAndy
It's because, until ECMAscript 262 edition 5, there was a big confusion if people who where using the constructor pattern, forgot to use the new keyword. If you forgot to use new when calling a constructor function in ES3, this referenced the global object (window in a browser) and you would clobber the global object with variables.
That was terrible behavior and so people at ECMA decided, just to set this to undefined.