What is this at the top level of a JavaScript script?
In a non-module script, this is the global object (window in browsers). In ES modules, top-level this is undefined. In Node.js CommonJS, top-level this is module.exports.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Global Execution Context and the this Keyword
To prevent accidental global pollution. ES modules are designed to be isolated. If you need the global object, use globalThis explicitly.
It creates the global object (window, global, or self), the global scope where top-level declarations live, and the global this binding pointing to the global object in non-module scripts.
module.exports, not global. This is different from browser scripts where this is window. In Node.js ES modules, top-level this is undefined.
Still have questions?
Browse all our FAQs or reach out to our support team
