title: Filereader output saved to variable
body: <p>I would like to ask you guys, how to save output of FileReader in JavaScript to a variable, or make the function where is the FileReader return the output.</p>
  
  <p>Here is also a bit of code:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;input type='file' id='inputFile'&gt;
  &lt;button id='btn'&gt;Save&lt;/button&gt;
  </code></pre>
  
  <p><strong>JAVASCRIPT</strong></p>
  
  <pre><code>function imgToBase64(file_input) {
      if (file_input.files &amp;&amp; file_input.files[0]) {
          var fileReader = new FileReader();
          fileReader.onload = function (event) {
              result = event.target.result;
              return result // ???
          };
          fileReader.readAsDataURL(file_input.files[0]);
      }
  }
  
  parameter = document.getElementById('inputFile');
  btn = document.getElementById('btn');
  
  btn.onclick = function() {
    variable = imgToBase64(parameter); //in this variable I would like to store the result from that function
  }
  </code></pre>
  
  <p>I found out that the FileReader is asynchronous and i need a callback or smth, but I don't fully understand how to do so.</p>
  
  <p>Thanks</p>