Question Bank

JavaScript Immutability and References Quiz

Difficulty: Medium

Lock down objects with `Object.freeze`, build read-only properties with `Object.defineProperty`, and reason about why React leans on immutable updates.

Question Bank
/

JavaScript Immutability and References Quiz

JavaScript Immutability and References Quiz

Lock down objects with `Object.freeze`, build read-only properties with `Object.defineProperty`, and reason about why React leans on immutable updates.

Question Bank
Medium
JavaScript
4 questions
quiz
immutability
references
interview-prep

968 views

5

Make obj reject all mutations by freezing it, then predict what happens when client code tries to reassign one of its keys in non-strict mode.

Examples

Example 1:

Input: Object.freeze(obj); obj.name = 'Jane'; console.log(obj.name)
Output: 'John'
Explanation: In non-strict mode the assignment silently fails; in strict mode it throws TypeError. Freeze stops top-level mutation only.