- What will the output be in the console if we run the following code in a browser?
try {
setInterval(() => {
throw new Error("Oops");
}, 1000);
} catch (ex) {
console.log("Sorry, there is a problem", ex);
}
We'd get a message saying that an uncaught error (Oops) has occurred. The console.log statement wouldn't be reached.
- Assuming that post 9999 doesn't exist, what would be the output in the console if we ran the following code in a browser:
fetch("https://jsonplaceholder.typicode.com/posts/9999")
.then(response => {
console.log("HTTP status code", response.status);
return response.json();
})
.then(data => console.log("Response body", data))
.catch (error => console.log("Error", error));
The key thing is that an HTTP error doesn't...