Global Variables in Node.js

Global Variables in Node.js

Global variable can be accessed anywhere in the project. 

Global variables can be initialized with a value and that value can be changed.

Regular variable can be accessed anywhere in the file.

Global variable can be defined by global object as below.

<%

global.globalVariable = "This can be accessed anywhere!";

console.log(globalVariable); // Output: "This can be accessed anywhere!"

%>

if you set the 'use strict' directive, Node will disable implicit globals and you will likely end up with an error at runtime rather than a working script.

 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

83242