var keyword in Browser vs var in Nodejs

Arun Rajeevan
1 min readMar 6, 2019

In browsers, the top-level scope is the global scope. This means that within the browser var something will define a new global variable.

In Node.js this is different. The top-level scope is not the global scope;
var something inside a Node.js module will be local to that module.

global object in Nodejs:

There is a global object in Nodejs runtime that has all the global objects.You can add into that global object to define any global variable

or Simple don’t use var while declaring a variable.It will automatically go into global

--

--