title: Getting the result object of FileReader()
body: <p>is there any way i can fetch the result object of a FileReader() without getting through a function ?</p>
  
  <p>i have made a sample code below:</p>
  
  <p><strong>HTML</strong>
      </p>
  
  <pre><code>&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;
  
  &lt;div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>var code = "lorem ipsum";
  
  $("input[type='file']").change(function() {
      var upload = this.files[0];
  
      var reader = new FileReader();
      reader.onload = function() {
          code = reader.result;
          $("div").append("&lt;label&gt;this should appear first: " + code + "&lt;/label&gt; &lt;br /&gt;");
      };
      reader.readAsDataURL(upload);
  
      $("div").append("&lt;label&gt; this should appear last: " + code + "&lt;/label&gt; &lt;br /&gt;");
  });
  </code></pre>
  
  <p>the problem with this code is that the <code>reader.onload = ...</code> line is skipped and is run right after the last line of the script. not the usual top to bottom reading of a code. and so, when this code is run, you will receive an exact result as below:</p>
  
  <pre><code>this should appear last: asd 
  this should appear first: data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/7QC+...
  </code></pre>
  
  <p>notice that <code>this should appear last</code> appears first before <code>this should appear first</code>. </p>
  
  <p>whereas as if according to the script if it is read from top to bottom, <code>this should appear first</code> must appear before <code>this should appear last</code>.</p>
  
  <p>this is where i apply my conclusion that the <code>reader.onload...</code> line is skipped all throughout and is run before the script ends.</p>
  
  <p>this is where my dilemma begins, i need to find an alternative code where i don't have to use a function on <code>reader.onload</code>. simply assigning <code>reader.onload = reader.result</code> does not work.</p>
  
  <p>with this current code, the first run of the script returns <code>code</code> as <code>lorem ipsum</code> and on the second run returns <code>data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/7QC+...</code>. but i need <code>code</code> to be <code>data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/7QC+...</code> right after the script is executed on its first time.</p>
  
  <p>sorry for my confusing explanation. i am not very fond of expressing myself in english since it is not my native language. thank you</p>