Alternative
Définition : Code
1
if (condition){
2
action1;
3
} else {
4
action2;
5
}
Exemple : Testez
See the Pen Alternative by BCMM-W2D (@bcmm-w2d) on CodePen.
Alternative
Définition : Code
Écriture simplifiée avec un opérateur ternaire
1
condition ? retour1: retour2;
Exemple : Testez
See the Pen cours-js-alternative-ternaire by BCMM-W2D (@bcmm-w2d) on CodePen.
Ternaire
Définition : Code
Selon
1
switch(X){
2
case 'a': action1; break;
3
case 'b': action2; break;
4
default: action3;
5
}
Exemple : Testez
See the Pen cours-js-alternative-switch by BCMM-W2D (@bcmm-w2d) on CodePen.
Switch