본문 바로가기

KDT핀테크프론트엔드개발자2기34

[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.
[JS] 데이터 - 얕은복사(Shallow copy) & 깊은 복사(Deep copy) 얕은복사(Shallow copy) & 깊은 복사(Deep copy) 참조형 데이터에 할당연산자를 사용했을 때 나타날 수 있는 문제 const user = { name: 'Flyda', age: 85, emails: ['dskjskjdad@gmail.com'] } const copyUser = user console.log(copyUser === user)//true user.age = 22 console.log('user', user)//user {name: 'Flyda', age: 22, emails: ['dskjskjdad@gmail.com']} console.log('copyUser', copyUser) //cop.. 2022. 4. 26.
[JS] 데이터 - Array (배열) 1. index, indexing, element(item) const numbers = [1, 2, 3, 4, 5] const fruits = ['apple', 'banana', 'cherry'] - index(인덱스) : 인덱스는 0부터 시작한다. 따라서 'apple'은 index = 0, 'banana'는 index=1이다! nubers의 1 또한 index =0이라는 것!! - indexing(인덱싱) : 배열 속의 데이터를 배열의 이름과 인덱스 번호로 접근할 수 있다. 예를 들면 numbers 배열 속의 데이터 '2'에 접근하고 싶다면 `numbers [1]`과 같이 그 배열의 이름과 인덱스 번호를 사용하면 된다. - element(요소) : 배열 속의 데이터를 element(요소)라고 부른다... 2022. 4. 25.