0

If/else statement or switch statement ??

in JavaScript, between d regular if/else statement and d switch statement, which is beta and in which case will one be beta Dan d other???

29th Nov 2016, 1:43 AM
Adekunle Oluwaseun Oladele
Adekunle Oluwaseun Oladele - avatar
3 Réponses
+ 2
Switch statements are strict in that you need to provide a default fall through case but they also give you more flexibility in that if statements work with boolean, switch statements can take on a larger variety of case statements for a Serene and known set of parameters a switch statement is preferred but when there are a variety of unknowns then if statements will work to your advantage.
29th Nov 2016, 4:02 AM
Eric Gitangu
Eric Gitangu - avatar
+ 2
From another point of view, your code should always be understandable by humans (just in case someone else has to maintain your code)... so a switch statement is far less complicated to read than a nested if-elseif-elseif-else statement.
29th Nov 2016, 6:36 AM
Álvaro
+ 1
thanks guys
29th Nov 2016, 11:56 AM
Adekunle Oluwaseun Oladele
Adekunle Oluwaseun Oladele - avatar