Object spread in ES2018, and Object.assign’s retirement

Merging objects meant Object.assign({}, a, b), and forgetting the empty first argument mutated a — a bug that shows up two components away from where it was written.

// before
const next = Object.assign({}, state, { loading: false });

// ES2018
const next = { ...state, loading: false };

// and the rest half, which is the more useful one
const { password, ...safe } = user;
res.json(safe);

The rest destructuring is what earns its place: removing a field from an object previously meant copying it and calling delete, which mutates and is slow on some engines. Both are shallow, so a nested object is shared between the copy and the original — which is the single most common misunderstanding and the source of state that changes when nothing appeared to change it.