Global Context
In the global execution context (outside of any function), this refers to the global object whether in strict mode or not.
// In web browsers, the window object is also the global object:
console.log(this === window); // true
a = 37;
console.log(window.a); // 37
this.b = "MDN";
console.log(window.b) // "MDN"
console.log(b) // "MDN"
// In Node REPL
console.log(this === global); // true
// In Node Module/file
console.log(this === global); // false
console.log(this === module.exports); // true
Note: You can always easily get the global object using the global
globalThisproperty, regardless of the current context in which your code is running.