オブジェクトの展開・マージ・残余プロパティの取得
// ── 基本: オブジェクトを展開して結合する ────────────────
const a = { x: 1, y: 2 };
const b = { z: 3, w: 4 };
const merged = { ...a, ...b };
console.log(merged); // { x: 1, y: 2, z: 3, w: 4 }
// ── 後から書いた方が上書きされる ─────────────────────
const base = { color: 'red', size: 'M', weight: 100 };
const updated = { ...base, color: 'blue', weight: 200 }; // 2つを上書き
console.log(updated); // { color: 'blue', size: 'M', weight: 200 }
console.log(base); // { color: 'red', size: 'M', weight: 100 } ← 変わらない
// ── React で state を更新する定番パターン ───────────────
const [user, setUser] = useState({ name: '田中', age: 25, city: '東京' });
// name だけ変えて他は維持
setUser(prev => ({ ...prev, name: '鈴木' }));スプレッドはObject.assignより可読性が高い。レストはプロパティの一部を除いた新オブジェクトを作るのに便利。