Question 6
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
const record = "Asha"; // expected an object like { name: "Asha" }
if ("name" in record) {
console.log("Has a name");
}
- A TypeError: in can only search an object – Cannot use 'in' operator to search for 'name' in Asha Correct
- B It prints Has a name
- C Nothing is printed
- D SyntaxError
Correct Answer: Option A
The right operand of in must be an object; primitives are not wrapped for in. Check the type first (typeof record === "object" && record !== null).
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!