0

Imagine this javascript code is inside an already busy loop:

if (a==0)
{
     d=6;
}else if (a==1)
{
     d=31;
}else if (a==2)
{
     d=null;
}

I thought of replacing it with:

var array=[6,31,null];
d=array[a];

Which would be faster? In case it is the array approach, is it faster to have this array as a global var? I am thinking "Yes, because if you make it local, the program becomes a bit slower because it has to declare the array every time". Thank you in advance.

0 Answers0