Object and Arrays - Reference VS Copy
Start with strings, numbers and booleans
let age = 100;
let age2 = age;
console.log(age, age2); //100, 100
age = 200;
console.log(age, age2); //200, 100Reference - array
// Let's say we have an array
const players = ['Wes', 'Sarah', 'Ryan', 'Poppy'];
// and we want to make a copy of it.
const team = players;
console.log(players, team); // ['Wes', 'Sarah', 'Ryan', 'Poppy'] x2
// You might think we can just do something like this:
team[3] = 'Lux';
console.log(players, team); // ['Wes', 'Sarah', 'Ryan', 'Lux'] x2Array copy
With Objects
Object copy
Object - one level deep
하지만 정말 every level deep이 필요하다면? (추천x)
Last updated