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 is the outcome of attempting to change the dept property of returnTarget after calling Object.freeze(returnTarget)?

  1. The dept property will change to "Finance"

  2. The dept property remains unchanged

  3. A new property can be added

  4. The entire object can be deleted

The correct answer is: The dept property remains unchanged

When you call `Object.freeze(returnTarget)` on an object in JavaScript, you make that object immutable. This means that its properties cannot be changed, added to, or removed. The `dept` property of `returnTarget` will remain unchanged because freezing the object prevents any alterations. This immutability applies to all properties of the object. When you try to assign a new value, such as "Finance," to the `dept` property after the object has been frozen, JavaScript will silently ignore the change in non-strict mode or throw a `TypeError` in strict mode, thus ensuring that the original state of the object is preserved. In summary, freezing an object guarantees that its properties stay intact, leading to the conclusion that the `dept` property remains unchanged after the object has been frozen.