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?
CONTEXT
I have an object page{} with a method battle().
In a choose_action() method from page, I call battle().
When battle() ends, choose_action is called again.
Battle() have event.listeners addressed to buttons with fixed ids ("attack", "defense", etc). When the img with the id "attack" is pressed, the attack()(Which is also a page{} method) function is called.
My point is, are the event.listeners created in battle() global? Or are they freed when battle() ends? I'm afraid calling battle() again will create doubled attack_event_listeners, that will make attack (n) times every click, n being the times battle() is called.