title: Find out if a Variable exists
body: <p>I would like to find out if a Javascript variable exists. This is what I have so far which was cobbled together from different forums:</p>
  
  <pre><code>function valueOfVar(foo){
  
      var has_foo = typeof foo != 'undefined';
  
      if(has_foo){
          alert('1 = true');
          return true;
      }
      else {
          alert('1 = false');
          return false;
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>Please note, I wish to pass in a
    string as foo. Example: valueOfVar(box_split[0]+'_2')</p>
  </blockquote>
  
  <p>Now, I don't think this works because it returns true when certain variables don't even exist. In fact, it seems to return true all the time.</p>
  
  <p>A JQuery implementation that works would also be great as I make use of this.</p>
  
  <p>Thanks all for any help</p>