What is the difference between scope in ES modules and classic scripts?
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.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Scope in ES Modules vs Scripts in JavaScript
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.
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
