Saturday, February 16, 2013

JavaScript: Conditional

var ans = (1 > 2) ? "Condition is true" : "Condition is false";

if (1 >2)
{
}
else if (1 < 2)
{
}
else
{
}

switch (aVar)
{
  case "a":
      break;
   case "b";
       break;
   default:
       break;
}

// another way to write an if
// all case are evaluated
var x = 10;
switch(true)
{
   case x ==0:
      break;
   case x >10:
    break;
   case x <= 10
     break;
}