Javascript: When reading/fetching data, is there an option that is use more between onreadystatechange and onload?
const xhr = new XMLHttpRequest();
xhr.responseType = 'json';
xhr.onreadystatechange = () => {
if(xhr.readyState === XMLHttpRequest.DONE){
console.log(xhr.response);
return xhr.response;
}
};
or
xhr.onload = function() {
if(this.status == 200){
console.log(this.responseText);
}
}
- Which is used more and why?
- Which is newer?
- If doing a interview question related to fetching, which would be more professional/impressive?