title: Availability / validity of variables within classes
body: <p>Normally I am using the sessionStorage-Object to store global variables, but what i fount out is, that variables that are defined outside Javascript Classes, are although available within them. I make an example below. So what i want to know is:</p>
  
  <p>What is the benefit of sessionStorage-Object vs. the usage of such "global" variables that are available everywhere? I do not want to make page reloads because i have a closed application.</p>
  
  <p>This is the HTML</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Test&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;!-- Klassen --&gt;
          &lt;script src="js/classes/Document.js"&gt;&lt;/script&gt;
  
          &lt;!-- Main --&gt;
          &lt;script src="js/javascriptklassen.js"&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is javascriptklassen.js</p>
  
  <pre><code>var globaleVariable='Ich bin im Parent Context -- ';
  var myDoc=new Document();
  
  globaleVariable='Ich bin auch im Parent Context -- ';
  var myDoc2=new Document();
  
  globaleVariable='Zusätzlich bin ich auch im Parent Context -- ';
  var myDoc3=new Document();
  </code></pre>
  
  <p>This is Document.js</p>
  
  <pre><code>var Document = function () {
      this.globaleVariable='Not in parent context';
      this.writeSomethingToHTML();
  }
  
  Document.prototype = {
          writeSomethingToHTML: function() {
              var aDiv = document.createElement("div");
  
              var globaleText = document.createTextNode(globaleVariable);
              aDiv.appendChild(globaleText);
  
              var localText = document.createTextNode(this.globaleVariable);
              aDiv.appendChild(localText);            
  
              document.body.appendChild(aDiv);
          }       
  }
  </code></pre>
  
  <p>The result looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/KBZ5v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KBZ5v.png" alt="Test in all browsers"></a></p>