slewis
slewis

Reputation: 11

Best way to set multiple global variables in jquery

I have 20 + global variables and 10+ associative array in one js file, and also I have some functions to calculate and to display. And I need to store those vlaues in localstorage. Do we have any best way to store the variables, arrays and functions? EX:

var country=region=detailOne=detailTwo='';
var websiteOne=webSitetwo=0;
var channel=[];

var RateCard={
                India:{a:0,b:0,c:0},
                Australia:{a:0,b:0,c:0}
               }

Upvotes: 0

Views: 156

Answers (1)

georg
georg

Reputation: 214959

Instead of a bunch of vars, use a single object:

var myData = {
   country: ...,
   region: ....
   etc

and then simply:

 localStorage.myData = JSON.stringify(myData);

However, you cannot store functions this way - why would you want to, anyways?

Upvotes: 2

Related Questions