2

I installed the node.js v6.9.1 and typed window but received only an error. In the Chrome js console, window prints "window" and if you click on the triangular link you can see all the window.whatever functions. How do I get that same result using the node shell?

Thanks.

mr.zog
  • 533
  • 1
  • 7
  • 26
  • Possible duplicate of [Does node.js have equivalent to window object in browser](http://stackoverflow.com/questions/19849136/does-node-js-have-equivalent-to-window-object-in-browser) – Rahul Desai Dec 01 '16 at 00:39

1 Answers1

3

You can't. There is no window in Node. Window is part of the browser which is totally absent in Node.

The Node Shell is referred to as the REPL

Window (from MDN)

The window object represents a window containing a DOM document; the document property points to the DOM document loaded in that window.

Community
  • 1
  • 1
peteb
  • 18,552
  • 9
  • 50
  • 62
  • @mr.zog: Weirdly the ECMAscript spec that defines the Javascript language actually requires the global object (window) to exist but does not specify its name. The spec simply calls it "the global object". Browsers have historically linked the global variable "window" to that global object but other interpreters like Actionscript (Flash) and node.js have decided to not link it to any variable. In any case, if you're not in strict mode then `this` when used outside of any function refers to the global object. So in the node shell you can use `this` instead of `window` – slebetman Dec 01 '16 at 02:13
  • @mr.zog: Note that the `this` trick also work in browsers. So in web browsers you can also type `this` instead of `window` – slebetman Dec 01 '16 at 02:14
  • Thanks again. This is quite helpful. – mr.zog Dec 01 '16 at 15:58