Question 7
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
class User {
constructor(name) { this.name = name; }
}
const u = User("Asha");
console.log(u.name);
- A TypeError: Class constructor User cannot be invoked without 'new' Correct
- B It prints Asha
- C It prints undefined
- D ReferenceError
Correct Answer: Option A
Unlike constructor functions, classes refuse to be called as plain functions. Write new User("Asha").
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!