The answers above are good and provide good insights, but I share the same opinion as shared in this google developers blog entry in that the main difference (from a practical perspective) is the convenience of the built-in promise returned from fetch
Instead of having to write code like this
function reqListener() {
var data = JSON.parse(this.responseText);
}
function reqError(err) { ... }
var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.onerror = reqError;
oReq.open('get', './api/some.json', true);
oReq.send();
we can clean things up and write something a little more concise and readable with promises and modern syntax
fetch('./api/some.json')
.then((response) => {
response.json().then((data) => {
...
});
})
.catch((err) => { ... });
fetch(url).then(function(data) (...));
is not simpler than usingXMLHttpRequest
to do the same thing? It may have lots of other features, but geez, it sure is simpler to use for common things. It IS a cleaned up API. – jfriend00