title: Uncaught TypeError: id name is null, whilst error checking should prevent this error
body: <p>I have a javascript module which is listens to an addEventListener, and when the event takes places, an image is being removed from the html. After removal of the image, when the element of interest is clicked again the following error is prompted:</p>
  <pre><code>Uncaught TypeError: ID_2 is null
  &lt;anonymous&gt; remove.js:9
  EventHandlerNonNull* remove.js:3
  EventListener.handleEvent* remove.js:2
  </code></pre>
  <p>Because of this, I added a check to see if the variable is present, but when I click the element for a 6th time, the error pops up again and from the debugging terminal it is shown that <code>ID2</code> from <code>ID_2.remove();</code> is causing the error. How can this error still be prompted with the 6th click? When my javascript first of all does not meet the condition count === 5, and second of all with ID_2 being null?</p>
  <pre><code>var count = 0;
  
  document.addEventListener('DOMContentLoaded', function(){
      document.querySelector(&quot;#ID_1&quot;).onclick = function(){
          if(count === 5){
  
          var ID_2 = document.querySelector(&quot;#ID_2&quot;);
          if(ID_2 !== 'null' ){ID_2.remove();}
          }
  
          else{count++;}
          }})
  </code></pre>