LearnFrenzy
Sign in Take a free test

Objects · Predict the Output · Question 9

Adding to a frozen object Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

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

main.js
const o = Object.freeze({ a: 1, inner: { b: 1 } });
o.a = 5;
o.inner.b = 5;
o.c = 1;
console.log(o.a, o.inner.b, o.c);
  • A 1 5 undefined Correct
  • B 5 5 1
  • C 1 1 undefined
  • D TypeError
Correct Answer: Option A

In a non-strict script, writes and additions on a frozen object are silently ignored. freeze is shallow, so inner can still change.

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