I have following code:
function SetStartDateIfNull(date, range_id) {
if (date || isEmpty(date)) {
switch (range_id) {
case 0:
date = date.getDate() - 1;
break;
case 1:
date = date.getDate() - 30;
break;
case 2:
date = date.getMonth() - 6;
break;
case 3:
date = date.getYear() - 1;
break;
case 4:
date = date.getYear() - 15;
break;
} //end switch
} //end if
return date;
} //end SetStartDateIfNull
my intention if date is null, I set date. I debugged the code. “if” statement is working. If date is null it entire the if block. But it skips the switch block. In debugging, range_id = 0; and date = ""; Why it skips the all switch block?
UPDATE
this code is working.
function SetEndDateIfNull(date) {
if (date || isEmpty(date)) {
date = new Date();
}
return date;
} //end SetDateIfNull
Thanks.
In your function, you are checking if the date is null, but in your cases you are trying to get date from undefined variable.
Working Demo