What happens to the name property after calling Object.seal(emp) and then delete emp.name?

Prepare for the Salesforce JavaScript Developer Exam. Utilize comprehensive quizzes, flashcards, and multiple choice questions with hints and explanations. Boost your exam readiness!

When you use Object.seal(emp), it prevents the addition of new properties to the object and marks all existing properties as non-configurable. This means that existing properties cannot be deleted or redefined.

In this case, since the name property already exists on the emp object and you attempt to delete it after sealing the object, the delete emp.name statement will have no effect. The name property remains unchanged because sealing the object has made it non-configurable, thus preventing its deletion.

This behavior highlights the purpose of the Object.seal() method, which is to allow the existing properties to be modified if they are writable, but to protect the structure of the object itself by disallowing any deletions or additions.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy