Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does node.js have equivalent to window object in browser

What I mean is does node.js have object that are global function methods of. Like this in browser:

function myGlobalFunction() {     console.log(this === window); } myGlobalFunction();  => true 
like image 206
IGRACH Avatar asked Nov 07 '13 23:11

IGRACH


People also ask

What is the equivalent of window in NodeJS?

log(global. foo); //return undefined... @spex: It works the same in node and the browser. In both cases, if you do var foo = 42 in the global environment, you'll be able to access foo as a property of the global object, which is window in the browser and global in NodeJS.

CAN NodeJS be used in browser?

js is a server-side JavaScript run-time environment. It's open-source, including Google's V8 engine, libuv for cross-platform compatibility, and a core library. Notably, Node. js does not expose a global "window" object, since it does not run within a browser.

How is NodeJS different from browser?

Unlike the browser where Javascript is sandboxed for your safety, node. js has full access to the system like any other native application. This means you can read and write directly to/from the file system, have unrestricted access to the network, can execute software and more.

Is window object in JavaScript?

Window is the object of browser, it is not the object of javascript. The javascript objects are string, array, date etc.


1 Answers

The closest equivalent in node is global. I'm not sure if it translates in all of the same ways, but if you open a REPL and type in this === global, it will return true.

Here's a discussion on the global object, though some it the information may be deprecated as it's pretty old: 'Global' object in node.js

like image 54
EmptyArsenal Avatar answered Oct 04 '22 06:10

EmptyArsenal