Facebook Pixel
The Shortest JavaScript Program and the Global Object

What does this point to at the global level in JavaScript?

The answer

In a non-module script, this points to the global object (window in browsers). In ES modules, top-level this is undefined.

More FAQs in The Shortest JavaScript Program and the Global Object

An empty file. Even with no code, the engine creates a global execution context, a global object (window in browsers, global in Node.js), and a global this binding pointing to the global object.

window in browsers, global in Node.js, self in Web Workers. ES2020 introduced globalThis to unify them, so globalThis always refers to the global object regardless of environment.

Yes, in browsers. Variables declared with var at the top level become properties of the window object. let, const, and class declarations do not become properties of window.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.