NoGlobalObject
DRAFT

Misconception:

Using the keyword this outside specific scopes yields undefined, as there is no global object.

Incorrect

There isn't a global object

Correct

There is always a global object

Correction
Here is what's right.

Before starting the execution, JavaScript creates a global object.

When we use the keyword this outside specific environments it always refers to this global object.

globalThis

JavaScript can run in very different contexts (a browser, a Web Worker, NodeJS, and so on…) and each of them used to have a special keyword to refer to the global object (window, self, global). Newer versions of the JavaScript specification have standardized globalThis as the proper way to refer to the global object from anywhere in the code.

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.