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>