How to minimize the use of global variables in JavaScript?

JavascriptWeb DevelopmentFront End Technology

A global variable has global scope which means it can be defined anywhere in your JavaScript code. To minimize the usage of global variables, use consistent variables around different parts of your project.

var myValue = {
   common: function(){
      //Add code
   },
   val1: {
      myVar1: "Demo String One",
      func1: function(){
         //Add some code
      },
   }
   val2: {
      myVar1: "Demo String Two",
      func1: function(){
         //Add another code
      },
   }
   val3: {
      myVar1: "Demo String Three",
      func1: function(){
         //Add another code here
      }
   }
};


raja
Published on 22-Jan-2018 15:41:56
Advertisements