I have been trying to save the data in stringAll but when I run Line 2(mentioned in comments), it does not show anything. For line 1, it prints the data to console. I am guessing this has got to do with the scope of the variable but I am not able to come up to a definite conclusion. Please help!!
let stringAll = ""
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
stringAll = this.responseText;
//Line 1: console.log(stringAll);
}
});
xhr.open("GET", "https://api.covid19api.com/total/dayone/country/india/status/confirmed");
xhr.send();
//Line 2: console.log(stringAll)