title: JavaScript: How to check if variable exists by variable name?
body: <p>I am having this issue. I have a script that checks if variable exists, because some scripts load asyncronously, like FB for Facebook or twttr for Twitter.</p>
  
  <pre><code>function whenAvailable(name, callback, interval) {
      interval || (interval = 100); // ms
      window.setTimeout(function() {
          if ((window.hasOwnProperty &amp;&amp; window.hasOwnProperty(name)) || window[name] || !!eval(name)) {
              return callback();
          } else {
              window.setTimeout(arguments.callee, interval);
          }
      }, interval);
  }
  </code></pre>
  
  <p>Looks like this </p>
  
  <pre><code>if ((window.hasOwnProperty &amp;&amp; window.hasOwnProperty(name)) || window[name] || !!eval(name)) 
  </code></pre>
  
  <p>does not work. IE throws error for 
  eval(name) -- e.g. if name = 'FB', it says it can't eval 'FB' which is undefined.</p>
  
  <p><code>window.hasOwnProperty(name)</code> does not work if <code>name == 'twttr.widgets'</code>.</p>
  
  <p><strong>Is there a universal and cross browser check for existence of var by var name?</strong></p>