Destructuring (구조분해)
·
Codeit/JavaScript
Destructuring (구조분해)- 배열이나 객체를 구조분해 배열 구조분해const rank = ['효준', '유나', '민환', '재하'];const macbook = rank[0];const ipad = rank[1];const airpods = rank[2];const coupon = rank[3];console.log(macbook); // 효준console.log(ipad); // 유나console.log(airpods); // 민환console.log(coupon); // 재하const rank = ['유나', '효준', '민환', '재하'];const [macbook, ipad, airpods, coupon] = rank;console.log(macbook); // 유나console.lo..
옵셔널 체이닝
·
Codeit/JavaScript
옵셔널 체이닝 (?.)const user = { name: "뽀로로", address: { city: "jeju" }, number: { location: "seoul", }, sayHello() { console.log("Hello world"); }};console.log(user.number); console.log(user && user.number && user.number.location); // undefinedconsole.log(user?.number?.location); // undefined -> null이나 undefined가 아니면 뒷값으로 넘어감console.log(user.sayHello?.()); //undefined -> sayHello의 반환..
모던한 프로퍼티 표기법
·
Codeit/JavaScript
객체 프로퍼티 간결하게 작성하기const user = { title: 'Codeit', birth: 2017, job: '프로그래밍 강사'}; - 변수의 할당된 값을 활용하여 프로퍼티 작성가능- 변수의 이름과 프로퍼티 이름이 동일하면 축약형으로 하나만 작성가능const title = 'Codeit';const birth = 2017;const job = '프로그래밍 강사';const user = { title, birth; job};console.log(user); // {title: "Codeit", birth: 2017, job: "프로그래밍 강사"}function getFullName() { return `${this.firstName} ${this.lastName}`;};const u..
효땡
기묘한 기묘원