Keep in mind, particularly with objects and arrays you can achieve immutability with object and array spread operators respectively as follows :
With objects:
let a = {x: 1}
let b = {...a}
b.x = 2;
console.log(a.x)
With arrays :
let a = ["one"]
let b = [...a]
b[0] = "two";
console.log(a.x)
Cheers !
Keep in mind, particularly with objects and arrays you can achieve immutability with object and array spread operators respectively as follows :
With objects:
let a = {x: 1} let b = {...a} b.x = 2; console.log(a.x) // still x === 1With arrays :
let a = ["one"] let b = [...a] b[0] = "two"; console.log(a.x) // still outputs as "one"Cheers !