I made this thread to share multiple alternatives in JavaScript to deal with conditions and statements so users can best pick their style and to broaden their JavaScript by examining my code. All of the code listed here is welcome for comments and feedback.
Code:
<script type="text/javascript">
xmlhttp_type=(window.XMLHttpRequest && "Standard") || (window.ActiveXObject && "ActiveX") || (window.createRequest && "IceBrowser") || "Unknown";
alert(xmlhttp_type);
</script>
The above accomplishes the same as:
Code:
<script type="text/javascript">
xmlhttp_type=window.XMLHttpRequest?"Standard":
window.ActiveXObject?"ActiveX":window.createRequest?"IceBrowser":"Unknown";
alert(xmlhttp_type);
</script>
which accomplishes the same as:
Code:
<script type="text/javascript">
switch (true)  {
   case !!window.XMLHttpRequest:
      xmlhttp_type="Standard";
      break;

   case !!window.ActiveXObject:
      xmlhttp_type="ActiveX";
      break;

   case !!window.createRequest:
      xmlhttp_type="IceBrowser";
       break;

    default:
      xmlhttp_type="Unknown";
       break;

}

alert(xmlhttp_type);
</script>
which accomplishes the same as:
Code:
<script type="text/javascript">
if(window.XMLHttpRequest)xmlhttp_type="Standard";
else if(window.ActiveXObject)xmlhttp_type="ActiveX";
else if(window.createRequest)xmlhttp_type="IceBrowser";
else xmlhttp_type="Unknown";
alert(xmlhttp_type);
</script>
which accomplishes the same as:
Code:
<script type="text/javascript">
xmlhttp_type=["Standard","ActiveX","IceBrowser","Unknown"][[window.XMLHttpRequest?1:0,window.ActiveXObject?1:0,window.createRequest?1:0,1].join("").indexOf("1")]
alert(xmlhttp_type);
</script>
Feel free to add to the list in order to help others gain a better perspective of JavaScript conditions.