I have a user database like this:
const user = {
subscription: {
plan: 'free_trial',
},
};
I need to check some condition before user changes plan.
const currentDate = new Date();
if (user.subscription.trialExpDate > currentDate) {
// do something
} else {
// trialExpDate is either undefined or <= currentDate
user.subscription.trialExpDate = currentDate;
}
My question is, for some users trialExpDate will be undefined. Is it okay to compare undefined against currentDate object? Or do I need to check if trialExpDate exist first?
user.subscription.trialExpDate? Is it a string ? Trynew Date(user.subscription.trialExpDate)user.subscription.trialExpDateis eitherundefinedOR adateobjectundefined > new Date();will always befalse.. I would have tested the value before comparing..