In nodejs, you can use the global object global to define global variables. All global variables are attributes of the global object. The definition syntax is "global. variable name="variable value";"; you can also use "global .variable name" statement to access the global variable.
The operating environment of this tutorial: windows7 system, nodejs version 12.19.0, Dell G3 computer.
There is a special object in JavaScript called the global object (Global Object). It and all its properties can be accessed anywhere in the program, that is, global variables.
In browser JavaScript, usually window is the global object, and the global object in Node.js is global. All global variables (except global itself) are properties of the global object. In Node.js we can directly access global properties without including it in the application.
Method to define global variables:
global.变量名="变量值";
Method to access global variables:
global.变量名
[Recommended learning: "nodejs Tutorial"]
The above is the detailed content of How to define global variables in nodejs. For more information, please follow other related articles on the PHP Chinese website!