title: I am try to under stand this javascript code but tired of it?
body: <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;body onload="myFunction()"&gt;
      &lt;script&gt;
      var go="globle";
      function myFunction() {
      var go="local";
      document.write(go);
           }
      document.write(go);
      &lt;/script&gt;
  
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>when I run this code it will print local.But when I run the following code:</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html&gt;
      &lt;body onload="myFunction()"&gt;
      &lt;script&gt;
      var go="globle";
      function myFunction() {
      var go="local";
          }
      document.write(go);
      &lt;/script&gt;
  
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>This code print globle.
  Why not the first code printing both local and globle.
  And also when I run first code my html body is also not executed.</p>