title: Why is my variable empty, not undefined in JS?
body: <p>I am trying to make a programming language. I have a global variable called textToRead, which is the text in the file. However, it's resulting in an empty variable.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
    &lt;p id="text"&gt;This is where your code will appear&lt;/p&gt;
    &lt;p id="test"&gt;This is where your code will appear&lt;/p&gt;
    &lt;p id="output"&gt;This is where you will see the output&lt;/p&gt;
    &lt;tr&gt;
      &lt;td&gt;Select a File to Load:&lt;/td&gt;
      &lt;td&gt;&lt;input type="file" id="fileToLoad"&gt;&lt;/td&gt;
      &lt;td&gt;&lt;button onclick="loadFileAsText()"&gt;Load Selected File&lt;/button&gt;
        &lt;td&gt;
    &lt;/tr&gt;
    &lt;button onclick="run()"&gt;Interpret .txt as code&lt;/button&gt;
    &lt;script&gt;
      let textToRead;
      function loadFileAsText() {
        var fileToLoad = document.getElementById("fileToLoad").files[0];
        var fileReader = new FileReader();
        fileReader.onload = function(fileLoadedEvent) {
          var textFromFileLoaded = fileLoadedEvent.target.result;
          document.getElementById("text").innerHTML = textFromFileLoaded;
        };
        fileReader.readAsText(fileToLoad, "UTF-8");
        document.getElementById("text").innerHTML = fileReader.result;
        textToRead = fileReader.result;
        document.getElementById("test").innerHTML = textToRead;
      }
  
      function run() {
        if (textToRead.includes("output")) {
          document.getElementById("output").innerHTML = textToRead;
        } else {
          document.getElementById("output").innerHTML = textToRead + "error";
        }
      }
    &lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  
  I'm not getting any errors, and my variable textToRead isn't undefined, because it's resulting in a value of nothing, not undefined. The part where you can view the page is working, but the variable used for parsing the string isn't.</p>