Discuss the differences and use cases of Object.freeze(), Object.seal(), and const.

Instruction: Explain how Object.freeze(), Object.seal(), and const differ and provide examples of their use cases.

Context: This question probes into the candidate's understanding of immutability and object configuration in JavaScript.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

const protects a variable binding from reassignment. It does not freeze the referenced object.

Object.seal prevents adding/removing own properties and makes their descriptors nonconfigurable. Existing writable data properties remain writable; already nonwritable properties do not become writable. An accessor's existing setter can still run...

Related Questions