Facebook Pixel

Does var become a property of window in an ES module?

No. In ES modules, top-level var, let, const, and class are module-scoped. They are not properties of window and are only accessible outside the module if explicitly exported.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Scope in ES Modules vs Scripts in JavaScript

In classic scripts, top-level var becomes a property of window and this is the global object. In ES modules, top-level variables are module-scoped (not global), this is undefined, and strict mode is automatic.

undefined. In classic scripts, top-level this is the global object (window). In ES modules, it is undefined to prevent accidental global mutation. Use globalThis if you need the global object.

Yes. Any file with import or export is automatically in strict mode. You do not need 'use strict'. This catches more bugs like accidental globals and duplicate parameter names.

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.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.