monthDateMapper(month) {
const months = {'Jan': '01', 'Feb': '02', 'Mar': '03'
,'Apr': '04', 'May': '05', 'Jun': '06'
,'July': '07', 'Aug': '08', 'Sep': '09'
, 'Oct': '10', 'Nov': '11', 'Dec':'12'}
let monthDate;
for(var monthAbrev in months) {
month === monthAbrev ? monthDate = months[monthAbrev] : monthDate = 'Invalid Value'
}
return monthDate
}
Presuming I hit my function with monthDateMapper('Apr'), why does my conditional never assign monthDate to be 04.
I've read a few articles on the subject of matching strings in Javascript; most of them say that this kind of type checking is never going to be true, even if both types are strings and the same value:
One of the answers suggested to use lodash _.isEqual(), this did not work. Also I tried converting lower-case on both sides, also trying to convert them both further to 2 strings. I confirmed they were both two strings through typeOf.
Is there a way around it?