Hi, I am a passionate web developer with a strong background in Computer Science. I have done M.Tech in Computer Science from IIT Kanpur. And currently working as a Principal engineer in MNC.
You mean if comparators are string then switch would be better? I don't think so, as matching the string the object key will take same amount of time same as switch.
constpositionInWeek=(dayOfWeek)=>{switch(dayOfWeek){case"Monday":case"Tuesday":return"Start of the week"case"Wednesday":case"Thursday":case"Friday":return"Middle of the week"case"Saturday":case"Sunday":return"End of the week"default:thrownewError("Not a week day")}}
This would be harder to understand in an object or if-else-if-chain.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Alex, didn't get the point.
You mean if comparators are string then switch would be better? I don't think so, as matching the string the object key will take same amount of time same as switch.
Maybe an oversimplified example may help:
This would be harder to understand in an object or if-else-if-chain.