diff --git a/notes/chap3_types_values_and_variables.md b/notes/chap3_types_values_and_variables.md index b88972a..784ef70 100644 --- a/notes/chap3_types_values_and_variables.md +++ b/notes/chap3_types_values_and_variables.md @@ -516,6 +516,24 @@ Symbol.keyFor(t) // => "shared" ## 3.7 The Global Object +**Global Object**: properties of this JS object are globally defined identifiers, and are available to a JS program. +* Usage: When JS interpreter starts (e.g. Node or new page in web browser), it creates a new global object and initialize its properties: + * Global constants: e.g. `undefined`, `Infinity`, and `NaN` + * Global functions: e.g. `isNaN()`, `parseInt()` (§3.9.2), and `eval()` (§4.12) + * Constructor functions: e.g. `Date()`, `RegExp()`, `String()`, `Object()`, and `Array()` (§3.9.2) + * Global objects: e.g. `Math` and `JSON` (§6.8) +* Initialized properties can be viewed as reserved words (尽管不是). + +Global object in Node: +* global object has property with name `global`. +* In Node, we can refer the global object using the name `global` + +Global obj in web browsers: +* **Window object** act as a global obj for all JS code in the browser window. +* Use `window` property of this global obj to refer it. + +Since ES2020, `globalThis` is used to refer to the global obj. + ## 3.8 Immutable Primitive Values and Mutable Object References ## 3.9 Type Conversions