title: updating variable value javascript
body: <p>I'm making a calender, where the user can click on an image to go to the previous year. 
  I have a global variable called currentYear, it is being used in the whole program.</p>
  
  <p>My question is:
  how can I change (update) its value once the user click that image? With my code, it does change but it doesn't update in the other statments.</p>
  
  <pre><code>    &lt;button onClick="dec()"&gt;test&lt;/button&gt;
      &lt;script&gt; 
      var currentDate = new Date();
      var currentYear = currentDate.getFullYear();
      function dec() { 
      currentYear--; 
      }​
      document.write(currentYear); // outside the function 
      &lt;/script&gt;
  </code></pre>