[자바스크립트] 데이터타입, rest operators, 구조분해 할당, 클래스

Dan·2022년 10월 12일
0

자바스크립트

목록 보기
1/4

참조형 데이터 타입

객체와 배열은 참조형 데이터 타입이다.
참조형 데이터 타입은 가짜복사 / 진짜 복사가 있다.

const person = {
  name : 'Max'
}
const secondPerson = person // 가짜 복사
// 객체가 아니라 person이 가리키고 있는 포인터를 복사하는 것
// 따라서 person의 name 을 변경하면 secondPerson에서도 변경됨
// 독립된 복사본을 만들기 위해서는 spread 연산자 사용
// const secondPerson = {...person}

rest operators

파라미터로 여러개 받을 경우 사용

function fc (...args){ return args.filter(el => el ===1 }
console.log(fc(1,2,3,4)) // [1]

구조분해할당

array destructuring

[a, b] = ['hello', 'max']
console.log(a) //hello
console.log(b)//max

object destructuring

{name} = {name:"max", age:"27"}
console.log(name) // max
console.log(age) // 27

클래스

프로퍼티 -> 클래스에 정의한 변수
메소드 -> 클래스에 정의한 함수

프로퍼티 & 메소드 선언 + 상속
es6
constructor 사용, this 키워드 사용
상속시에 constructor 안에 super() 사용
es7
constructor 사용 x, this 키워드 사용하지 않으며 메소드 선언시에는 애로우 펑션 사용
상속시에 super() 키워드 안해줘도 됨

0개의 댓글