Ask any question about JavaScript here... and get an instant response.
Why does `window` object not exist in Node.js while it does in a browser environment?
Asked on Nov 12, 2025
Answer
The "window" object is specific to browser environments as it represents the global context of the web page. In Node.js, the global context is represented by the "global" object instead, as Node.js is designed for server-side JavaScript execution.
// Browser environment
console.log(window); // Logs the window object
// Node.js environment
console.log(global); // Logs the global objectAdditional Comment:
✅ Answered with JavaScript best practices.- In a browser, "window" is the global object that provides access to the DOM, browser history, and other web APIs.
- In Node.js, "global" is the global object that provides access to Node-specific APIs like modules, process, and more.
- The environments differ because browsers and Node.js have different purposes and capabilities.
Recommended Links:
