There are different methods to use condition statements
-
method:
var x = 3, y; if (x == 4) y = 1; else if (x == 3) y = 2; else y = 3; alert(y); -
method:
var x = 3,
y = x == 4 ? 1 : x == 3 ? 2 : 3;
alert(y);
- method:
var x = 3,
y = x == 4 && 1 || x == 3 && 2 || 3;
alert(y);
My question now: Which method should I use? And why?
Aucun commentaire:
Enregistrer un commentaire