객체 생성자 function Animal( type, name, sound ) { this.type = type; this.name = name; this.sound = sound; this.say = function() { console.log(this.sound); }; } const dog = new Animal('개', '슈슈', '슈슝~'); const cat = new Animal('고양이', '줍줍', '줍줍이~'); dog.say();//슈슝~ cat.say();//줍줍이~ prototype prototype 은 동일한 클래스인 객체들끼리 값이나 함수를 공유할 수 있다. function Animal( type, name, sound ) { this.type = type; this.name ..
reduce - 배열의 모든원소를 활용하여 한줄로 연산이 가능하다. - 한꺼번에 처리할 수 있어서 매우 유용한 연산자다. 알면좋다. reduce 예제 1 - sum 연산으로 forEach문과 비교 forEach 반복문을 사용했을 때 console.clear(); const numbers = [ 1,2,3,4,5 ]; let sum = 0; numbers.forEach( n => { sum += n; }); console.log(sum); // 15 reduce를 사용했을 때 - 아주 간단하다 3줄이 한줄로 줄여진다. - arrayName.reduce( (누적값, 현재값) => 내부연산 , 초기 누적값 ); 으로 구성되어 있다. acc는 accumulator의 약자로, 누적값을 의미한다. curr은 cur..
shift 와 unshift - shift, unshift 함수 모두 배열의 원본이 변한다. shift - 배열의 맨앞의 원소값을 추출 const numbers = [10, 20, 30, 40]; const value = numbers.shift(); console.log(value);// 10 console.log(numbers);// [20, 30, 40] unshift - 배열의 맨앞에 원소값을 추가 const numbers = [10, 20, 30, 40]; numbers.unshift(0); console.log(numbers);// [0, 10, 20, 30, 40] pop 과 push - pop, push 함수 모두 배열의 원본이 변한다 pop - 배열의 맨뒤의 원소값을 추출 const nu..
splice 배열에서 시작인덱스로부터 몇개를 제거할지를 나타낸다. splice 수행 후 원본배열에 저장된 값이 변한다. console.clear(); const numbers= [10, 20, 30, 40, 50]; const index = numbers.indexOf(30); const spliced = numbers.splice( index, 1 ); // index(2) 번호를 시작으로 1개만 갖고오겠다. console.log(spliced); // [30] console.log(numbers); // [10, 20, 40, 50] slice 배열에서 시작인덱스부터 끝인덱스까지의 부분 배열을 나타낸다. slice 수행 후 원본배열에 저장된 값이 보존된다. console.clear(); const n..
배열 내장함수 - forEach 1. 기본적인 반복문 const animals = ["개", "고양이", "햄스터", "도마뱀"]; for (let i = 0; i < animals.length; i++) { console.log(animals[i]); } 2. for ... of 를 사용한 반복문 const animals = ["개", "고양이", "햄스터", "도마뱀"]; for (let animal of animals) { console.log(animal); } 3. forEach - 내부 함수를 regular function 으로 표현 const animals = ["개", "고양이", "햄스터", "도마뱀"]; animals.forEach( function (animal) { console.l..
배열 (array) 인덱스는 0부터 시작한다. array를 구성하는 요소의 타입 제한이 없다. const array = [1, 2, 3, 4, 5]; console.log(array); const array2 = [1, "후딘", { type: "esper" }]; console.log(array2[2]); const objects = [{ name: "슈슈" }, { name: "두부" }, { name: "산이" }]; console.log(objects[0]); console.log(objects[1]); console.log(objects[2]); console.log(objects[3]); // undefined push & length push - 배열에 새로운 항목을 추가 length - 배..
객체 정의 key: name, age, type, weight const dog = { name: "슈슈", age: 14, type: "슈나우저", weight: 7.2 }; console.log(dog); console.log(dog.name); console.log(dog.age); const iron_man = { name: "토니 스타크", actor: "로버트 다우니 주니어", alias: "아이언맨" }; const captain_america = { name: "스티브 로저스", actor: "크리스 에반스", alias: "캡틴 아메리카" }; function print(hero) { const text = `${hero.alias}(${hero.name}) 역할 받은 배우는 ${hero..
함수블록 return 코드는 함수 종료를 의미함. ES6 - JS 2015년도 버젼 - const, let 등도 해당됨. [참고용] ES6 와 ES5(2015년 이전 자바스크립트) 비교하면서 어느부분이 달라졌는지를 보여준다. ECMAScript 6: New Features: Overview and Comparison Constants Constants Support for constants (also known as "immutable variables"), i.e., variables which cannot be re-assigned new content. Notice: this only makes the variable itself immutable, not its assigned content (f..
- Total
- Today
- Yesterday
- vscode
- Nest.js
- 클린아키텍쳐
- 한달어스
- jest
- IT용어
- TDD
- 갓생살자
- 미완
- nestjs jest
- 바이트디그리
- typeORM
- 습관개선
- node.js
- 디지털디톡스
- Mongoose
- TypeScript
- gem
- MongoDB
- nestjs
- 개발용어
- git
- 참고
- 나도 할 수 있다
- RDBMS
- 한달독서
- 스마트폰중독
- OS
- MySQL
- Jekyll
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |