title: Trying to understand the scope of global javascript variables
body: <p>I have this <strong>global variable</strong> in my <strong>javascript</strong> code:</p>
  
  <pre><code>var currentcount=0;
  </code></pre>
  
  <p>Later on I try to update currentcount, and it is enclosed in the following manner:</p>
  
  <pre><code> function next(){
     ...
      if(userAnswer === myQuestions[overallcount].correctAnswer){
        ...
         var tempcount = currentcount;
          for(tempcount in myQuestions.length-1){
            if(currentdiff&lt;myQuestions[tempcount].difficulty)
              currentcount=tempcount;
          }
        ...
    }
  </code></pre>
  
  <p>When I output currentcount, it is still 0.</p>
  
  <p>I am simply having trouble understanding what the scope of currentcount is, and why it is not updating in the way I want it to.
  tempcount does update to whatever currentcount is, but currentcount never updates.</p>
  
  <p>If I do something like:</p>
  
  <pre><code> function next(){
     ...
      if(userAnswer === myQuestions[overallcount].correctAnswer){
        ...
         var tempcount = currentcount;
         currentcount++;
        ...
      }
    }
  </code></pre>
  
  <p>currentcount does update, but again, it's not the way I want it to.</p>
  
  <p>Please provide an explanation as to why it is so and if there is a solution to update currentcount in the manner I want it to.</p>
  
  <p>Thank you in advance.</p>