What is the difference between Object.freeze() and Object.seal() in JavaScript?

What is the difference between Object.freeze() and Object.seal() in JavaScript?

a) Object.freeze() makes an object immutable, while Object.seal() prevents new properties from being added
b) Object.freeze() allows new properties, while Object.seal() does not
c) Object.seal() removes properties, while Object.freeze() adds properties
d) They are identical

Answer:

a) Object.freeze() makes an object immutable, while Object.seal() prevents new properties from being added

Explanation:

The Object.freeze() method makes an object immutable, preventing changes to existing properties or the addition of new properties. The Object.seal() method prevents new properties from being added, but allows changes to existing properties.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top