Hey Simon, nice article! Dev.to recommended it to me and I really enjoyed the read. Very well written and good points raised.
To foment the discussion, I'd like to point out something
Nested if statements and switch cases
The good part
Switch cases are way more readable than if's statements when we're talking about multiple conditionals.
The problems
There are are a lot of problems with switch statements, and a lot of people smarter than me have proved that. Instead of giving you some quotes, I'll drop the entire article because to me these are must read.
Object literals! They are as readable as switch statements. You can be as creative as you want with them, so you're not forced to break any pattern or standard.
Instead of
switch(dayOfTheWeek)){case0:day="Sunday";break;case1:day="Monday";break;case2:day="Tuesday";break;case3:day="Wednesday";break;case4:day="Thursday";break;case5:day="Friday";break;case6:day="Saturday";break;default:thrownewError("Hey! We have only 7 days in the week");}
How about
constdayOfTheWeek={0:"Sunday",1:"Monday",2:"Tuesday",3:"Wednesday",4:"Thursday",5:"Friday",6:"Saturday",};console.log('day of the week:',dayOfTheWeek[newDate().getDay()]);
Hey Simon, nice article! Dev.to recommended it to me and I really enjoyed the read. Very well written and good points raised.
To foment the discussion, I'd like to point out something
Instead of
How about
Hi! Thanks!
I totally agree with you. I used a list as an example but objects are definitely better than switch cases when there are many cases!
Thanks for sharing π