0

Switches

Can anyone please explain switches in JavaScript?

5th Aug 2022, 4:40 PM
Nomeena Abbasi
Nomeena Abbasi - avatar
2 Antworten
+ 4
Check this code, i covered 2 examples where switch is better than if/else. First is when you have lot of data - like your task is to print month number, and you have month name, here switch have easier syntax, you type less code, so you have less place to make typo and is easier to maintain/fix bug/change this code. Second example is if you have multiply cases with same output - in my example i checked month name and displayed in what quarter of year is this month, here we have 3 months what are in same quarter. And this is best example of when to use swith. https://code.sololearn.com/WeHzedEcG3Ph/?ref=app
5th Aug 2022, 5:29 PM
PanicS
PanicS - avatar
0
need example and explanation
5th Aug 2022, 4:44 PM
Nomeena Abbasi
Nomeena Abbasi - avatar