The console is not only a place to see errors but it can be used to execute code as well. This is useful for quick debugging, especially on a page that may have another library of code incorporated within it. The console has scope to all JavaScript loaded on the page, as long as it's accessible from the top-level window object. We wouldn't expect to have access to a function's internal variables, but if the browser can access the data, we can access it in the console.
Open the fetch.html and fetch.js files in the debugger folder and take a look. Here's the fetch.js file:
const fetchAttempt = (url) => {
fetch(url)
.then((response) => {
return response
}).then((data) => {
if (data.status === 500) {
console.log("We got a 500 error")
}
console.log(data)
}).catch((error) => {
throw new Error(error)
})
}
It's a bare-bones fetch request with the URL to be fetched...