function formatToStandardizedDate(from, to){
    const from_date = moment(from);
    if(to){
        let to_date = moment(to);
    }else{
        let to_date = null;
    }
}
console.log(formatToStandardizedDate("2017-04-19 00:00:00",null))
What's wrong with my code above? if to is null it at least assign a null to to_date but I got error of to_date of undefined error. Why?
 
    