title: Store variable from one event handler to be used by another event handler in Javascript
body: <p>Imagine this Javascript code:</p>
  <pre><code>&quot;use strict&quot;;
  
     var codePc = function (){        
     var code=[ ];    
     // code not important
     // code not important for the question: print the values to an html list    
      Return code
  
  var codePlayer = function (list1){              
     var Intrud = [ ];    
     // code not important
     //code not important for the question: print the values to an html list    
      Return intrud
          
  var codeCompare = function (list2){    
     var equal = [ ];    
     // code not important for the question: it should compare list 1 with list2
     // code not important for the question: print the values to an html list    
      Return equal
  
  
  function main(){ 
      
     document.getElementById(&quot;button1&quot;).addEventListener(&quot;click&quot;, function(){codePc ();});    
     document.getElementById(&quot;button2&quot;).addEventListener(&quot;click&quot;, function(){codePlayer (code);}); //line 2    
     document.getElementById(&quot;button3&quot;).addEventListener(&quot;click&quot;, function(){codeCompare (intrud);});            
   };   
  
  
  document.addEventListener(&quot;DOMContentLoaded&quot;, function(event){ main()});
  </code></pre>
  <p>When I click on button1, I run the function <code>codePC</code>. The function returns code.</p>
  <p>When I click on button2, I run the function <code>codePlayer</code>. The function returns intrud.</p>
  <p>When I click on button3, I run the function <code>codeCompare</code>. The function returns equal.</p>
  <p>How can I use the var code, produced when I clicked on button 1, to feed the function when I click in the button 1?</p>
  <p>How can I save the variables code, intrud and equal, as global variables for later use?</p>
  <p>When I run the 3 function by this way, it is possible to save the lists in a variable?</p>
  <p>I just can't do :</p>
  <pre><code>Var codeKeep = document.getElementById(&quot;button1&quot;).addEventListener(&quot;click&quot;, function(){codePc ();});
  </code></pre>