LearnFrenzy
Sign in Take a free test

Objects · Find the Error · Question 10

Error: stringifying a circular object Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

The code below stops with an uncaught error. Which statement correctly describes the problem?

main.js
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links