What is this in a Node.js CommonJS module top level?
module.exports, not global. This is different from browser scripts where this is window. In Node.js ES modules, top-level this is undefined.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Global Execution Context and the this Keyword
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.
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.
Still have questions?
Browse all our FAQs or reach out to our support team
