Safe object merging; freezing & sealing
Merge objects without surprises, avoid prototype pollution, and protect data with Object.freeze and Object.seal.
Why safe merging?
Goal: Merge safely and protect state.
- Shallow merge with spread or Object.assign
- Avoid prototype pollution by filtering keys
- Use Object.create(null) for safe targets
- freeze and seal to lock objects

Shallow merge (spread)
Use spread (or Object.assign({}, a, b)) to make a new object; do not mutate inputs.
// Shallow merge with spread keeps sources unchanged
const a = { x: 1, y: 2 };
const b = { y: 9, z: 3 };
// Later keys win on conflicts
const merged1 = { ...a, ...b };
console.log("a:", a);
console.log("b:", b);
console.log("merged1:", merged1);

All lessons in this course
- Input validation, escaping basics
- Safe object merging; freezing & sealing
- Error boundaries (conceptual) without frameworks