title: What is Javascript Event Listener's scope?
body: <p>In C, if I don't dynamically malloc Anything inside a function, it is free'd when the function ends. I have no clue how Javascript (in special, event listeners) works in that sense. The question is, if a event listener is declared inside a function, is it killed when the function ends or it keeps listening?</p>
  
  <hr>
  
  <p>CONTEXT </p>
  
  <p>I have an object <code>page{}</code> with a method <code>battle()</code>.</p>
  
  <p>In a <code>choose_action()</code> method from page, I call <code>battle()</code>.</p>
  
  <p>When <code>battle()</code> ends, <code>choose_action</code> is called again. </p>
  
  <p><code>Battle()</code> have <code>event.listeners</code> addressed to buttons with fixed ids ("attack", "defense", etc). When the img with the id "attack" is pressed, the <code>attack()</code>(Which is also a <code>page{}</code> method) function is called. </p>
  
  <p>My point is, are the <code>event.listeners</code> created in <code>battle()</code>  global? Or are they  freed when <code>battle()</code> ends? I'm afraid calling battle() again will create doubled <code>attack_event_listeners</code>, that will make attack (n) times every click, n being the  times <code>battle()</code> is called. </p>