Chapter XXI · The `this` Keyword
Global Context
In the global execution context, `this` refers to the global object (`window` in browsers, `global` in Node.js).
01 How It Works
Think of the main root administrator control terminal of a system facility.
When code runs outside any function or object scope, `this` points directly to the root global runtime container.
example.js
console.log(this === window); // true (in browser environment)
1. Execute top-level script code.
2. Evaluate `this` in global scope.
3. Access global object properties.
02 Practical Example
Here is how you might see this concept applied in real-world code:
practical.js
var globalVar = "Test";
console.log(this.globalVar); // "Test" (attached to global object when using var)
Key Takeaway
In global scopes, `this` points directly to the root runtime environment object.