According to this explanation in MDN:
- in the global context,
this
refers to the global object - in the function context, if the function is called directly, it again refers to the global object
Yet, the following:
var globalThis = this;
function a() {
console.log(typeof this);
console.log(typeof globalThis);
console.log('is this the global object? '+(globalThis===this));
}
a();
... placed in file foo.js
produces:
$ nodejs foo.js
object
object
is this the global object? false