DEV Community

Cover image for Starting the year with a simple JS question
David Armendáriz
David Armendáriz

Posted on

Starting the year with a simple JS question

Look at the following code:

const getData = () => Promise.resolve("OK")

try {
  getData().then(data => {
    if(data === "OK") {
      throw new Error("I am an error")
    }
  })
} catch(err) {
  console.log("I caught an error here:", err)
}
Enter fullscreen mode Exit fullscreen mode

What do you think is going to happen? Is the console.log statement going to be executed? Why or why not?

How can we refactor this code so that it works as expected?

Watch the solution in my Youtube channel! https://www.youtube.com/watch?v=PB0FSbUFulc&ab_channel=DavidArmend%C3%A1riz

Top comments (0)