JavaScript globalThis ObjectJavaScript can access the global object using the global object property. The global object in JavaScript is called a window in a web browser. It is also referred global or web worker, Depending on the environment. The JavaScript frameworks with web servers use the globalThis property uniformly to get to the global object. Why do we use the globalThis object?
Global keyword and its environment tableThe following table shows the javascript output environment and its supported global keyword.
SyntaxThe following syntax uses in the script tag to operate a global object. It is directly used in the console and other output tabs. ExamplesThe multiple examples show the javascript variable with the global data in the output tab. Example 1 The following basic example shows gloabalThis variable with the process in the console tab. Output The image shows the output of the global object. ![]() Example 2 The following basic example shows gloabalThis variable with other functions in the console tab. Output The image shows the output of the global object. ![]() Example 3 The following basic example shows gloabalThis variable with the console tab. Output The image shows the output of the global object. ![]() Example 4 The following basic example shows gloabalThis variable with the alert tab. Output The image shows the output of the global object. ![]() Example 5 The following basic example shows gloabalThis variable with the onclick function. Output The image shows the output of the global object. ![]() Example 6 The following basic example shows gloabalThis variable with the typeof function. Output The image shows the output of the global object. ![]() Compatible BrowsersThe javascript globalThis object is supported by the below browsers.
ConclusionThe "objectThis" is referred to javascript as ES11 or ES2020. It is available in ECMA Script 2020. The globalThis object is used to create cross-platform code, meaningful code that can run in various JavaScript environments.
Next TopicJavaScript Logical Assignment Operators
|