An immutable collection is data whose existing structure is not edited. Changes are represented by creating a new structure from the old one. This approach fits declarative programming, where expressions compose toward a result instead of manipulating shared objects step by step. section 1.1.1
Compare the two approaches:
- Mutation edits an existing object or array, such as adding an item with push. section 1.1.1
- Immutability derives a result from the original collection, such as filtering passwords without storing or editing the original array. section 1.1.1
- React props follow the same read-only rule: a component can read its properties but should not edit or add them. section 2.5
function countGoodPasswords(passwords) {
return passwords.filter(p => p.length >= 9).length;
}
This compact example derives a new filtered array and immediately reads its length, illustrating a non-mutating collection operation. section 1.1.1
Read props without changing them
A component may inspect this.props and use its values to render. React freezes the props object internally with Object.freeze(), so updates belong in the parent context rather than inside the component. section 2.5























