title: JS removeEventListener with function inside
body: <p>I've created a function search with an event listener on a button. The problem is that the removeEventListener isn't working because init() is inside it to execute. Thus the EventListener is replicated everytime I click the button. If I remove init() all is fine. Maybe i misunderstand someting about it?</p>
  <p>Also if i remove the function search and only use const I know it fires ones. But the whole point is that i need to use search.</p>
  <pre><code>function search(data) {
    const clickHandler = () =&gt; {
     console.log('search');
  
     init();
   };
  
   document.getElementById('search').removeEventListener('click', clickHandler);
   document.getElementById('search').addEventListener('click', clickHandler);
  }
  
  search(data);
  
  function init() {
   console.log('hello');
  }
  
  console results:
  first time; hello
  second time; hello hello
  third time; hello hello hello hello 
  </code></pre>