LearnFrenzy
Sign in Take a free test

Objects · Predict the Output · Question 15

Comparing objects three ways Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 15 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
const a = { x: 1 };
const b = a;
const c = { x: 1 };
console.log(a === b, a === c, JSON.stringify(a) === JSON.stringify(c));
  • A true false true Correct
  • B true true true
  • C false false true
  • D true false false
Correct Answer: Option A

b refers to the same object as a; c is a different object with the same content, which only the string comparison sees.

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