title: Global variable and addEventlistener
body: <p>Here is the problem: I would like to have global variable X which takes value of alpha. With code below, value for X in console is always zero. </p>
  
  <pre><code>var X = 0; 
  
  window.addEventListener("deviceorientation", handleOrientation, true);
  
  function handleOrientation(event) {
      var alpha = Math.round(event.alpha);  
      X = alpha;
  }
  
  console.log(X);
  </code></pre>
  
  <p>EDIT: 
  I wanted to do something like</p>
  
  <pre><code>var X = 0; 
  
  window.addEventListener("deviceorientation", handleOrientation, true);
  
  function handleOrientation(event) {
      var alpha = Math.round(event.alpha);  
      X = alpha;
  }
  
  function f(x){ return x*x }
  
  f(X);
  </code></pre>
  
  <p>Now I understand that I have to put f(X) within function handleOrientation. I guess there is not other way around?</p>