Q: 9
A developer creates an object where its properties should be immutable and prevent
properties from being added or modified.
Which method should be used to execute this business requirement ?
Options
Discussion
Option D is right.
Object.freeze() makes the object immutable so properties can't be added or changed, which matches exactly what’s asked. Nice clear question-see this kind pop up a lot in practice sets.Its D, had something like this in a mock and it was Object.freeze().
D is right here. Object.freeze() is the only valid JavaScript method among these that fully locks an object so you can't add or modify properties. C looks tempting but it's a fake method, kind of a trick option. Pretty sure most practice exams use D too.
Yeah D, Object.freeze(). None of the others make objects immutable in JS.
D, saw this type in some exam reports. Object.freeze() is the way to fully lock down object properties.
D , Object.freeze() is the only real method here. Freezes the object so you can’t add or change properties. The rest aren’t even valid JS methods. Pretty confident unless I’m missing something obvious.
D imo since Object.freeze() is the actual JS method to stop both changing existing properties and adding new ones. None of the other options are real methods for this. Not 100 percent but can't think what else would fit.
Probably D here. Object.freeze() is literally the built-in way to lock an object's properties in JavaScript, stops both additions and changes. The other options aren’t real JS methods for immutability. Pretty sure about this but someone shout if I missed a trick.
Not C, pretty sure D is the only real method in JavaScript for making an object truly immutable. The other options aren't valid methods, so D stands out. C is a trap, but doesn't exist in JS as an object method. Disagree?
I don’t think it’s D. C sounds more like it would lock changes, right?
Be respectful. No spam.