Possible Duplicate Way to differentiate between declared variable vs undeclared
I want to explain clearly my problem here. I have this condition.
if(//condition1)
var x1 = 1;
else if(//condition2)
var x2 = 2;
else if(//condition3)
var x3 = 3;
This way I can have only one variable declared. Now I want to print the variable which is declared. How can I do that?
This is a more realistic example of what I am trying to do:
var d_pattern=/d{1}/;
var dd_pattern=/d{2}/;
var ddd_pattern=/d{3}/;
var dddd_pattern=/d{4}/;
if(dddd_pattern.test(formatString))
var dddd=this.getDayName();
else if(ddd_pattern.test(formatString))
var ddd=this.getDayNameAbbr();
else if(dd_pattern.test(formatString))
var dd=this.getDateFormatted();
else if(d_pattern.test(formatString))
var d=this.getDate();