Control flow pattern when checking for nonexistent variables
<p>I saw the following pattern and tried adapting it to my own use:</p>

<pre><code>var request = window.ActiveXObject ?
  new ActiveXObject('Microsoft.XMLHTTP') :
  new XMLHttpRequest;
</code></pre>

<p>Simplifying:</p>

<pre><code>var request = window.ActiveXObject ?
  "is ActiveX" : "not ActiveX";
document.write(request + "&lt;br&gt;");
// I get not ActiveX (Chrome)
</code></pre>

<p>Now when I try:</p>

<pre><code>var notX = "x"; 
  var j = x ? "has x" : "no x";
  document.write(j + "&lt;br&gt;");
  // console error: x is not defined
</code></pre>

<p><a href="http://jsfiddle.net/4mn8n/1/" rel="nofollow">http://jsfiddle.net/4mn8n/1/</a></p>

<p>Nothing gets outputted. What makes <code>window.ActiveXObject</code> different from <code>x</code> that the program continues to <code>document.write</code> but not in the case of <code>x</code>?</p>

<p><strong>-- More Importantly</strong></p>

<p>What's a robust pattern I can use to replace the above?</p>
