Mid JavaScript

How do you handle errors in JavaScript?

Using try...catch...finally or Promise .catch().

Example:

try {

throw new Error("Something went wrong!");

} catch (err) {

console.error(err.message);

} finally {

console.log("Cleanup code");

Intermediate

More from JavaScript Tutorial

All questions for this course