Immutability
Last updated
Last updated
let test = "Hello";
const testFn = (input) => {
test += "World";
}
testFn(test);
console.log(test) // Hello// Array
let ages = [42, 22, 35];
ages.push(8);
console.log(ages); // 42, 22, 35, 8
// Object
let p = {name:"Nee", age: 30};
p.age = 31;
console.log(p); // {name: "Nee", age:31}let test = ["Hello"];
const testFn = (input) => {
test.push("World");
}
testFn(test);
console.log(test) // [Hello, World]
let test2 = {key:"Hello"};
const testFn = (input) => {
test2.key = "World";
}
console.log(test2); // {key: World}// Array
let test = ["Hello"];
test = [...test, "World"];
// Object
let p = {name:"Nee", age: 30};
p = {...p, age: 31};
console.log(p);