Skip to content

Commit b549f8e

Browse files
committedSep 1, 2024
Add globalThis question
1 parent d129186 commit b549f8e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed
 

‎README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -8849,7 +8849,7 @@ The execution context is created when a function is called. The function's code
88498849
88508850
**[⬆ Back to Top](#table-of-contents)**
88518851
8852-
1. ### How to find the number of parameters expected by a function?
8852+
468. ### How to find the number of parameters expected by a function?
88538853
The function's object has a **length** property which tells you how many formal parameters expected by a function. This is a static value defined by the function, not the number of arguments the function is called with(__arguments.length__). The basic usage of length propery is,
88548854
88558855
```javascript
@@ -8898,6 +8898,26 @@ The execution context is created when a function is called. The function's code
88988898
88998899
**[⬆ Back to Top](#table-of-contents)**
89008900
8901+
469. ### What is globalThis, and what is the importance of it?
8902+
Nowadays JavaScript language is used in a wide variety of environments and each environment has its own object model. Due to this fact, there are different ways(syntax) to access the global object.
8903+
8904+
1. In web browser, the global object is accessible via `window`, `self`, or `frames`.
8905+
2. In Node environment, you have to use `global`.
8906+
3. In Web workers, the global object is available through `self`.
8907+
8908+
The `globalThis` property provides a standard way of accessing the global object without writing various code snippet to support multiple environments. For example, the global object retuned from multiple environments as shown below,
8909+
8910+
```javascript
8911+
//1. browser environment
8912+
console.log(globalThis); // => Window {...}
8913+
8914+
//2. node.js environment
8915+
console.log(globalThis); // => Object [global] {...}
8916+
8917+
//3. web worker environment
8918+
console.log(globalThis); // => DedicatedWorkerGlobalScope {...}
8919+
```
8920+
**[⬆ Back to Top](#table-of-contents)**
89018921
89028922
<!-- QUESTIONS_END -->
89038923

0 commit comments

Comments
 (0)
Please sign in to comment.