Node.js global variable global object

In Node.js , a .js file is a complete scope (module, module). Therefore, variables declared by var are only valid in the current .js file, not globally. The global global object is independent of all .js (module, module).

In JavaScript , variables declared by var are bound to the window object (global object) by default.


demo.js:

global.a = 666; // Global variables are in the global object.
a = 555; // Equivalent to global.a = 555; Without var, the directly declared variable is a global variable. The global variables in node are all in the global object.
console.log(global.a);


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326062830&siteId=291194637