title: Why is my variable undefined in the second if statement?
body: <p>I'm trying to reuse the same variable in a second <code>if</code> statement from the first <code>if</code> statement and I get the warning that my variable is <code>undefined</code> when I throw an alert on it.</p>
  
  <p>How could I make this variable retain its value on the second <code>if</code> statement? I'm only copying part of the code for you to see what I'm talking about. I am trying to use <code>foundRangeStart</code> in the second if statement for <code>ESNEnd</code>, which was previously used in the first <code>if</code> statement for <code>ESNStart</code>. </p>
  
  <p>Why is <code>foundRangeStart</code> set to <code>undefined</code> in the second <code>if</code> statement?</p>
  
  <pre><code>if ($(this).attr("id") == "ESNStart") {
      var esnStart = [];
      esnStart[0] = esn_to_num(enteredData);
      var item;
      var rangesFoundStart = [];
  
      rangesFoundStart[0] = -1; // Set defaut value as -1 for the corresponding entry in the "rangesFound" array
      for (var x in ranges) { // Inner loop over items in ranges object
          item = esnStart[0];
          if (item &gt;= ranges[x].min &amp;&amp; item &lt;= ranges[x].max) {
              rangesFoundStart[0] = x;
          }
      }
  
      if (rangesFoundStart[0] &gt;= 0) {
          foundRangeStart = rangesFoundStart[0];
      }
  
      if (foundRangeStart &amp;&amp; foundRangeStart &gt;= 0) {
          $("#STxModel").val(ranges[foundRangeStart].StxName);
          $("#TxSpacing").val(ranges[foundRangeStart].rtumodel);
      }
  }
  if ($(this).attr("id") == "ESNEnd") {
      var esnEnd = [];
      esnEnd[0] = esn_to_num(enteredData);
      var item;
      var foundRangeEnd;
      var rangesFound = [];
      rangesFound[0] = -1; // Set defaut value as -1 for the corresponding entry in the rangesFound array
      for (var x in ranges) { // Inner loop over items in ranges object
          item = esnEnd[0];
          if (item &gt;= ranges[x].min &amp;&amp; item &lt;= ranges[x].max) {
              if (rangesFound[x] == foundRangeStart) {
                  rangesFound[0] = x;
                  var foundone = rangesFound[0] = x;
                  alert(foundone + foundRangeStart);
              }
          } else {
              alert(alert_total);
          }
  
      }
  }
  </code></pre>