Question 10
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
const team = { name: "Core" };
const lead = { name: "Asha", team };
team.lead = lead; // team → lead → team …
console.log(JSON.stringify(team));
- A TypeError: Converting circular structure to JSON – team refers to itself through lead Correct
- B It prints {"name":"Core","lead":{"name":"Asha"}}
- C It loops forever
- D It prints [Circular]
Correct Answer: Option A
JSON cannot represent cycles. Store an ID instead of the object (lead: { name, teamName: "Core" }) or use a replacer that skips seen objects.
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!