The below JavaScript If/Else statement works correctly in identifying if the browser is IE11, with the result being that in IE the console prints "Internet Explorer" and in all other browsers prints "Not Internet Explorer":
if (window.document.documentMode) {
console.log("Internet Explorer");
}
else {
console.log("Not Internet Explorer");
}
However if I place something like a Fetch in the Else statement (which is not compatible with IE and should also not be read by IE) I will get a Syntax Error in the IE console:
if (window.document.documentMode) {
console.log("Internet Explorer");
}
else {
console.log("Not Internet Explorer");
fetch('https://randomuser.me/api/?results=10')
.then(response => response.json())
.then(data => console.log(data));
}
SCRIPT1002: Syntax error pointing to the first response of the Fetch:
.then(response => response.json())
Could someone advise what I'm doing wrong?