JavaScript · Middle · Question 32 of 75
What does this code print?
const cfg = Object.freeze({ db: { host: "a" } });
cfg.db.host = "b";
console.log(cfg.db.host);- ✓Correct answer:
"b":freezeis shallow; the nested object isn't frozen - 2
"a":freezefreezes the object all the way down - 3
TypeError: properties of a frozen object can't be changed
Explanation
Object.freeze prevents adding, removing and changing properties of the object itself only. Nested objects remain mutable. Deep freezing is done with a recursive function.