Ask any question about JavaScript here... and get an instant response.
Why does `window` object work in the browser but not in Node.js?
Asked on Oct 31, 2025
Answer
The "window" object is specific to web browsers and represents the global context of a web page, while Node.js uses a different global object called "global" for its runtime environment.
// Browser environment
console.log(window === this); // true
// Node.js environment
console.log(global === this); // falseAdditional Comment:
✅ Answered with JavaScript best practices.- In a browser, "window" is the global object and represents the browser window or tab.
- In Node.js, the global object is "global", and it does not equate to "this" in the same way as "window" does in browsers.
- Each environment has its own global object to provide context-specific functionalities.
Recommended Links:
