DEV Community

Discussion on: Deleting a property from a Javascript Object without Mutation

maswerdna profile image
Samson Andrew

I think this is application specific.

The object might have correct value somewhere but will be different at other place

JavaScript objects are not stuffs you throw around as you like. No matter the number of places where you use them, they still have a single reference. When you mutate an object from a certain function, you should expect the changes to reflect in every other place where it's being referenced.

If I delete person.worth from a certain place in my app, I want all active references to know that person is now worthless. Not that I would make it worthless in some part of the UI and worth a billion in other parts.

Generally, use what is best for your use case.

devcer profile image
Santosh Viswanatham Author

Yes! In the end it is up to what is best for your use case and as per your application. This is about why it is not recommended to have a best case where you mutate the objects, that becomes impossible to track mutations when the size of your application grows and a number people work on the same code. The fundamental part of Redux is to avoiding mutations, so this is about how a delete operation can be done without mutation. If Mutation has been working well for you so far then go for it. 🎊