emjayess
12/1/2010 - 5:34 PM

javascript's flexible ternary

javascript's flexible ternary

// the agility of javascript's ternary operation...
// lots of folks don't seem aware of the subsequent assignments available

function ternary(a,b) {
  var c,d,tis='';
  c = (d = a==b) ? tis='tis true' : tis='tis false';
  return [c,d,tis];
}
console.log(ternary(true,true));
console.log(ternary(true,false));
console.log(ternary(false,false));