loading...

re: Hoist Your Vars! (Variable Hoisting in JavaScript) VIEW POST

TOP OF THREAD FULL DISCUSSION
re: I am curious, why is your variable being mutated in the catch block? that block is for errors
 

A good example of when you might want to do this is if it’s a known exception and you are going to hand wave it away.

(async () => {
let result
try {
  // catch network issues
  const response = await fetch('https://example.com')
  // catch non-json data
  const data = await response.json()
  // catch inaccessible object
  result = data.messages
} catch(e) {
  result = { messages: [] }
}
})().then().catch()
Code of Conduct Report abuse