1

I have a function that takes a test document text and writes it to a variable. Within the function, I can print the variable out to the console and it is populated correctly, but when I try to read it outside of the function it is undefined. I'm not sure what I am doing incorrectly.



 <script>


      csvFile = "";

      grabData();

      async function grabData(){
          const response = await fetch('testURL');
          csvFile = await response.text();
          console.log(csvFile); //Correct Data
            }

      console.log(csvFile) //Undefined
    </script>

MasonAngus
  • 11
  • 2
  • I don't think he is asking the same thing, it's just a coincidence that in his example he is using a async function, same thing happens if your function is not async – Javier Heisecke Jun 26 '19 at 18:34

0 Answers0