I would say the problem is with user.status = status this is the part where you're mutating an object rather than creating a new one. Regardless of whether that function returns a reference or a clone, the point at which a side effect is introduced is that line.
You can never assume an external function is returning a safe-to-mutate result.
Also you're calling getTaskById instead of getUserById 🙂
Hi Jack, thanks for getting that typo (that's what happens when you're writing an article in the middle of the night!). The original code was more complicated and was ideed about "tasks" 😉
And you're right on all aspects. My intention is to make devs aware on how we can create code that is more reliable, be as a "consumer" or "producer" of the code.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I would say the problem is with
user.status = status
this is the part where you're mutating an object rather than creating a new one. Regardless of whether that function returns a reference or a clone, the point at which a side effect is introduced is that line.You can never assume an external function is returning a safe-to-mutate result.
Also you're calling getTaskById instead of getUserById 🙂
Hi Jack, thanks for getting that typo (that's what happens when you're writing an article in the middle of the night!). The original code was more complicated and was ideed about "tasks" 😉
And you're right on all aspects. My intention is to make devs aware on how we can create code that is more reliable, be as a "consumer" or "producer" of the code.