[JS] 데이터 - 전개 연산자
전개 연산자 ... const fruits = ['apple', 'banana', 'cherry'] console.log(fruits)//['apple', 'banana', 'cherry'] console.log(...fruits)//apple banana cherry //console.log('apple', 'banana', 'cherry') function toObject(a,b,c) { return { a: a, b: b, c: c } } console.log(toObject(...fruits)) console.log(toObject(fruits[0], fruits[1],..
2022. 4. 26.
[JS] 데이터 - 데이터 불변성 (Immutability)
데이터 불변성 (Immutability) 원시 데이터 : String, Number, Boolean, undefined, null 불변 참조형 데이터 : Object, Array, Function (함수도 콜백(함수의 인수)로 사용할 수 있기 때문!) 가변 같은 주소를 바라볼 때, 하나의 변수에서 값이 수정되도 다른 변수에서도 수정된 값이 나옴 (주의!!) 원시 데이터 let a = 1 let b = 4 console.log(a, b, a === b)//1 4 false b = a console.log(a, b, a === b)//1 1 true a = 7 console.log(a, b, a === b)//7 1 false let c = 1 // 기존의 1이 들어있는 메모리 주소를 바라보게 됨! cons..
2022. 4. 26.