Do not change those non-primitive function arguments without understanding the significant implications of your action.
Programming languages have pass by reference
and pass by value
to pass arguments to a function. Javascript passes values for primitives, but references when you are trying to pass objects.
Changing arguments within a function will change the arguments for ever.
|
|
It is a disaster if the world is treated as Mr. Anderson.
The simplest way to avoid this is by localizing the object in the function. You can do this with a spread operator or a rest operator.
|
|
In the above code we copy the original object and make any changes locally within the function. The changes do not impact the object passed as argument.