javascript - How to write in shorthand form if / else if / else? -


is there shorthand if / else if / else statement? example, know there's 1 if / else statement:

var n = $("#example div").length; $("body").css("background", (n < 2) ? "green" : "orange"); 

but how write following in shorthand syntax above?

var n = $("#example div").length;  if (n < 2) {     $("body").css("background", "green"); } else if (n > 2) {     $("body").css("background", "blue"); } else {     $("body").css("background", "orange"); } 

it exist it's highly un recommended because it's pretty hard read , maintain.

var n = $("#example div").length,     color;  color = (n < 2) ? 'green' :          (n > 2) ? 'blue'  : 'orange';  $("body").css("background", color); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -