jquery - javascript ternary condition operation -


i want achieve below logic using javascript ternary operation. possible?

if(condition1){     console.log("condition1 pass"); } else if(condition2){     console.log("condition2 pass"); } else{     console.log("it different"); } 

sure, have have 1 ternary inside another:

put else if condition inside : part.

console.log(     condition1         ? "condition1 pass"         : condition2             ? "condition2 pass"             : "it different" ); 

it's best not syntax mistakable , slim, could, however, move function or iife if it's inside function , return result directly reduce loop:

function testcondition(condition1, condition2){     if(condition1){         return "condition1 pass";     } else if(condition2){         return "condition2 pass";     }     return "it different"; }  var conditionalpass = (function(condition1, condition2){     if(condition1){         return "condition1 pass";     } else if(condition2){         return "condition2 pass";     }     return "it different"; })(condition1, condition2); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -