Short for else if

How to write an abbreviated expression for else if?

if (showvar == "instock"){ //show available } else if (showvar == "final3"){ //show only 3 available } else { //show Not available } 

I know writing when there is only if and else . But how to write it when there is an else if ?

 (showvar == "instock")? //show available : //show Not available 
+5
source share
1 answer

You simply insert else if on the false side false else also just false . So ...

 (showvar == "instock") ? show available : ((showvar == "final3") ? show only 3 available : show Not available); 
+6
source

Source: https://habr.com/ru/post/1245451/


All Articles