Recall & Review
beginner
What does the
throw statement do in JavaScript?The
throw statement stops normal execution and creates an error. It sends a value (usually an Error object) that can be caught by try...catch blocks.Click to reveal answer
beginner
How do you create a custom error message when throwing an error?
You create a new Error object with a message, like
throw new Error('My message'). This message helps explain what went wrong.Click to reveal answer
beginner
What happens if you throw an error outside of a
try...catch block?The program stops running and shows the error message in the console or environment. This is called an uncaught error.
Click to reveal answer
intermediate
Can you throw any type of value in JavaScript?
Yes, you can throw any value like strings, numbers, or objects. But it is best practice to throw Error objects for better debugging.
Click to reveal answer
beginner
Why is it useful to throw errors in your code?
Throwing errors helps you catch problems early, stop wrong actions, and give clear messages about what went wrong. It makes your code safer and easier to fix.
Click to reveal answer
What keyword is used to create an error intentionally in JavaScript?
✗ Incorrect
The
throw keyword is used to create an error intentionally.Which of these is the best way to throw a custom error message?
✗ Incorrect
Using
throw new Error('message') creates a proper Error object with a message.What happens if an error is thrown but not caught?
✗ Incorrect
An uncaught error stops the program and shows the error message.
Can you throw a number as an error in JavaScript?
✗ Incorrect
JavaScript allows throwing any value, but Error objects are recommended.
Why should you throw errors in your code?
✗ Incorrect
Throwing errors helps stop wrong actions and gives clear messages about problems.
Explain how the
throw statement works and why it is useful.Think about what happens when something goes wrong in your code.
You got /4 concepts.
Describe the difference between throwing a string and throwing an Error object.
Consider what makes debugging easier.
You got /4 concepts.