Question 9
Back to Exercise
What does the following JavaScript code print (console output, as in Node.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!