title: Why event listener cannot read property?
body: <p>I am new at JavaScript and I'm trying some events. The goal here is to click at some text and display a message. I have a <code>p</code> element in my html like this:</p>
  <pre><code>&lt;p id=&quot;tab&quot;&gt;Click me&lt;/p&gt;
  </code></pre>
  <p>At the .js file I tried this and nothing happened. The console yells me this:</p>
  <blockquote>
  <p>&quot;Uncaught TypeError: Cannot read property 'addEventListener' of null&quot;.</p>
  </blockquote>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var demo=document.getElementById("tab");
  
  demo.addEventListener("click", go);
  
  function go(){
      alert("Hey");
  }</code></pre>
  </div>
  </div>
  </p>
  <p>The code above resides in a separate .js file</p>