Skip to content

Commit cdea09f

Browse files
authored
💁 Provide the environment of each global variable
Each environment has its own object model and provides a different syntax to access the global object. In the web browser, for example, the global object is accessible via window, self, or frames. In Node.js, however, these properties don’t exist, and you must use global instead. In Web Workers, only self is available.
1 parent cf24491 commit cdea09f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,12 @@ console.log(greetign);
324324

325325
#### Answer: A
326326

327-
It logs the object, because we just created an empty object on the global object! When we mistyped `greeting` as `greetign`, the JS interpreter actually saw this as `global.greetign = {}` (or `window.greetign = {}` in a browser).
327+
It logs the object, because we just created an empty object on the global object! When we mistyped `greeting` as `greetign`, the JS interpreter actually saw this as:
328+
329+
1. `global.greetign = {}` in Node.js
330+
2. `window.greetign = {}`, `frames.geetign = {}` and `self.greetign` in browsers.
331+
3. `self.greetign` in web workers.
332+
4. `globalThis.greetign` in all environments.
328333

329334
In order to avoid this, we can use `"use strict"`. This makes sure that you have declared a variable before setting it equal to anything.
330335

0 commit comments

Comments
 (0)