私は最近、基本的な選択ステートメントに Snippet 1 の代わりに Snippet 2 を使い始めました。これは少し型にはまらないように思えるので、パフォーマンスの違いがあるかどうか、または一方が他方よりも読みやすいように見えるかどうかを知りたいと思いました。
スニペット 1
function foo() {
if(case1){
//...
} else if (case2) {
//...
} else if (case3) {
//...
} else{
// catch other cases
}
}
スニペット 2
function foo() {
if(case1){
//...
return;
}
if(case2){
//...
return;
}
if(case3){
//...
return;
}
// catch other cases
}