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

Practice this question and more.


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

  1. The name property is deleted successfully

  2. The name property remains unchanged

  3. A new name property can be added

  4. The object is completely frozen

The correct answer is: The name property remains unchanged

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.