Question 4
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
class OtpError extends Error {
constructor(message) {
this.name = "OtpError";
this.message = message;
}
}
throw new OtpError("OTP expired");
- A It throws OtpError: OTP expired
- B TypeError: name is read-only
- C ReferenceError: a derived constructor must call super() before using this Correct
- D SyntaxError
Correct Answer: Option C
Call super(message) first; it initialises the Error part of the object, including message and stack.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!