Mostly we write programs that deal with changing data.The way we change values of variables can lead to unexpected bugs in a software project. If you are dealing with primitive data types then there is no need to worry. In cases where you are working with referential data types, then care must be taken to avoid unnecessary bugs.
Let's look at the code below:
From the above code, b references a primitive value. We then assign c to the same value as b. The value of c was change and it did not affect that of b because both are primitive types and changes affect the values.
Unlike variable m and n. we assign m to n and the change made to n affects m. This is because arrays are non-primitive hence they are copied to the same reference object, so changes will affect each other.
ES6 brings on board native functions to execute immutable operations and that is the solution we will use to solve the mutability issue of object assignments.
NB: Please Read and critique on how the article can be made better.