Strings numbers and booleans are copied by value. If we'll change one variable, the other variable will not change.
Arrays are copied by reference.It means, that if one of these arrays will be changed, the other also will be changed. It works like that, because in variable we store the reference to the particular array
If we need a copy of array by value we have 4 options:
.slice()
method const newArr = [].concat(originalArr)
const newArr = [...originalArr]
const newArr = Array.from(originalArr)
Objects also are copied by reference.It means, that if one of these objects will be changed, the other also will be changed. It works like that, because in variable we store the reference to the particular object
If we need a copy of object by value, we can use this method
const obj2 = Object.assign({}, obj, {newProp:34, originalProp: newValue})