title: Three.js, appendChild and returning
body: <p>This is actually something I've solved, but for curiousity sake, I was wondering if someone could explain why this is the case?</p>
  
  <p>Here's my html:</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html&gt;
  
          &lt;head&gt;
              &lt;script src="three.min.js"&gt;&lt;/script&gt;
              &lt;script src="OrbitControls.js"&gt;&lt;/script&gt;
              &lt;script type="text/javascript" src="webgl.js"&gt;&lt;/script&gt;
          &lt;/head&gt;
  
          &lt;body style="margin: 0;"&gt;
  
          &lt;/body&gt;
  
      &lt;/html&gt;
  </code></pre>
  
  <p>and my JS:</p>
  
  <pre><code>    var scene, camera, renderer;
  
      init();
  
      animate();
  
      function init(){
  
          scene = new THREE.Scene();
  
          var width = window.innerWidth, height =  window.innerHeight;
  
          renderer = new THREE.WebGLRenderer({antialias:true});
          renderer.setSize(width, height);
          document.body.appendChild(renderer.domElement);
  
      }
  </code></pre>
  
  <p>This does not work, I get "Uncaught TypeError: Cannot read property 'appendChild' of null "</p>
  
  <p>But when I move my webgl.js script to the body, it renders the canvas element properly.  </p>
  
  <p>Why does this happen?  Why does my script need to be in the body to append the dom element?  The renderer object returns an canvas in my console, so what's the issue?  </p>