Enforcing the rules of your dataintermediate
A cart that can hold the same product twice, or a quantity that can go to zero, is a bug you will chase through the UI forever — the rules belong in the data layer.
A cart with rules: no duplicate lines, quantities that cannot reach zero, and a total that is always right.
Adding the same product twice gives one line of quantity 2, and no quantity can reach zero.
Published in full, before you start — every point is one of these and there is nothing else. Each one runs your code; it is not a search for keywords.
A cart that can hold the same product twice, or a quantity that can go to zero, is a bug you will chase through the UI forever — the rules belong in the data layer.
map, filter, find and reduce replace almost every loop you would otherwise write — knowing which one returns what is the single highest-leverage thing in JavaScript.