Facebook Pixel

Do var variables become properties of window in JavaScript?

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.

Verify This Answer

Cross-check this information using these trusted sources:

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.

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

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

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.