DEV Community

Discussion on: What is your favourite function()?

Collapse
 
_bigblind profile image
Frederik 👨‍💻➡️🌐 Creemers • Edited

I don't really have a favorite function, because it's all about using the right one to solve a problem. ut I like functions that make things simpler, so I think I'd pick fetch(). Because before, making HTTP requests from JavaScript looked like this

var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();