title: Waiting until a variable exists with typeof causes an infinite loop
body: <p>I need a function that waits until a variable comes into existence.</p>
  
  <pre><code>function wait(variable, callback) {
      if (typeof variable !== "undefined")
          callback();
      else
          setTimeout(function () {
              wait(variable, callback);
          }, 0)
  }
  </code></pre>
  
  <p>Calling this function with the example code below causes an infinite loop.</p>
  
  <pre><code>var a;
  wait(a, function(){console.log('success')});
  setTimeout(function(){a=1}, 1000)
  </code></pre>
  
  <p>Why?</p>