URL details: fridayrelease.guru/clean-code-js/functions/avoid-side-effects-2/
URL title:
Avoid side effects (part 2) - Let's release on Friday!
URL description:
Avoid Side Effects (part 2) Bad: const addItemToCart = (cart, item) => { cart.push({ item, date: Date.now() }); }; Good: const addItemToCart = (cart, item) => { return [...cart, { item, date: Date.now() }]; }; In JavaScript, primitives are passed by value and objects/arrays are passed by reference. In the case of objects and arrays, if your function makes a change in a shopping cart array, for example, by adding an item to purchase, then any other function that uses that cart array will be affected by this
URL last crawled:
2024-07-26
URL speed:
24.400 MB/s,
downloaded in 0.001 seconds
We found no external links pointing to this url.