JavaScript
-
10-1. JavaScript Set의 모든 것JavaScript 2023. 4. 7. 21:37
I. Set 이란? 중복되지 않는 값들의 집합 - 표준 내장 객체 중 하나 ✨배열과의 차이: - 동일한 값을 여러 번 포함할 수 없음 - 값들의 순서가 무의미함 1. 기본 사용법 // Set 생성 const set1 = new Set(); // add 메서드 - 요소 추가 set1.add(1); set1.add('A'); set1.add(true); console.log(set1);// Set(3) {1, 'A', true} - 이미 포함된 요소는 추가하지 않음!! // 이미 포함된 요소는 추가하지 않음 set1.add(1); set1.add(true); console.log(set1);// Set(3) {1, 'A', true} - 메서드 체이닝 가능 - size 프로퍼티 : 요소의 개수 // size..
-
9-3. JavaScript Symbol 자료형JavaScript 2023. 4. 7. 19:40
I. Symbol 이란? 다른 값과 절대 중복되지 않는 유일무이한 값 - 원시 타입 1. 기본 생성과 활용 (new 사용하지 않음) const mySymbol = Symbol(); console.log(typeof mySymbol, mySymbol);// symbol Symbol() 2. 문자열 값을 인자로 줄 수 있음 - 해당 심벌에 대한 설명일 뿐, 각 심벌의 값은 유일무이 const symbol1 = Symbol('hello'); const symbol2 = Symbol('hello'); console.log(symbol1, symbol2);// Symbol(hello) Symbol(hello) ✨객체에서의 활용 객체의 키로 사용시 : [ , ] 로 감쌈 const obj = { [Symbol('x..
-
9-2. JavaScript BigInt 자료형JavaScript 2023. 4. 7. 19:13
I. Number.MAX_SAFE_INTEGER : 더 큰 정수를 다루기 위한 자료형 - 매우 큰 정수를 다뤄야 하는 특수한 경우에 사용 console.log( Number.MAX_SAFE_INTEGER// 9007199254740991 ); ✨number 타입으로 안정적으로 표현할 수 있는 가장 큰 정수 - 9007199254740991 (2^53 -1) - 아래의 방법들로 생성 const bigInt1 = 9007199254740991n; // 끝에 n을 붙임 const bigInt2 = BigInt(9007199254740991); const bigInt3 = BigInt('9007199254740991'); const bigInt4 = BigInt(0x1fffffffffffff) // 900719..
-
9-1. JavaScript 2진법, 8진법, 16진법과 비트 연산자JavaScript 2023. 4. 7. 19:05
I. 다른 진법들 1. 2진법 (binary) - 0b 뒤로 숫자 0, 1를 붙여 표현 [ 0b1, 0b10, 0b11, 0b100, 0b101 ].forEach(i => console.log(i))// 1 2 3 4 5 2. 8진법 (octal) - 0o 뒤로 숫자 0 ~ 7를 붙여 표현 [ 0o7, 0o10, 0o100, 0o1000, ].forEach(i => console.log(i))// 7 8 64 512 3. 16진법 (hexadecimal) - 0x 뒤로 숫자 0 ~ 9, A ~ F를 붙여 표현 [ 0x9, 0xA, 0xB, 0xC, 0xd, 0xe, 0xf, 0x10, 0xFFFFFF ].forEach(i => console.log(i))// 9 10 11 12 13 14 15 16 16..
-
8-3. JavaScript JSON의 모든 것JavaScript 2023. 4. 7. 17:19
I. JSON (JavaScript Object Notation) - 복잡한 구조를 가질 수 있는 데이터를 한 줄의 문자열로 표현 - 서버와 클라이언트 등 데이터들을 주고받는 주체들 사이에 널리 사용 II. JSON 객체의 정적 메서드 1. stringify - 객체를 문자열로 직렬화 (serialize) const person = { name: '김달순', age: 23, languages: ['Korean', 'English', 'French'], education: { school: '한국대', major: ['컴퓨터공학', '전자공학'], graduated: true, } }; const personStr = JSON.stringify(person); console.log(typeof person..
-
8-2. JavaScript 프로퍼티 어트리뷰트(property attributes)JavaScript 2023. 4. 7. 16:39
I. 프로퍼티 어트리뷰트(property attributes) 객체의 프로퍼티가 생성될 때 엔진에 의해 자동 정의되는 상태 ✨프로퍼티에는 두 종류가 있음 const person = { // ⭐️ 1. 데이터 프로퍼티들 fullName: '홍길동', ageInNumber: 25, // ⭐️ 2. 접근자 프로퍼티들 get name () { return this.fullName .split('') .map((letter, idx) => idx === 0 ? letter : '*') .join(''); }, get age () { return this.ageInNumber + '세'; }, set age (age) { this.ageInNumber = Number(age); } } console.log( per..
-
8-1. JavaScript Object 의 모든 것JavaScript 2023. 4. 7. 16:13
I. Object 클래스 1. 이제까지 배운 자바스크립트 객체들의 원형 console.log( new String('ABC') instanceof Object,// true new Number(123) instanceof Object,// true [] instanceof Object,// true (function () {}) instanceof Object,// true globalThis instanceof Object// true ); - 각각 따로 출력해서 [[Prototype]] 펼쳐보기 2. 생성자 함수 // 빈 객체 생성 console.log( new Object(),// {} new Object(null),// {} new Object(undefined),// {} ); // 각 값에 적..
-
7-4. 배열의 스프레드(spread), 디스트럭쳐링(destructuring)JavaScript 2023. 4. 7. 15:21
I. 스프레드 (spread) 1. 기본 문법 const arr1 = [1, 2, 3]; const arr2 = [...arr1]; console.log(arr2);// [1, 2, 3] 2. 활용 ① 배열을 다수의 인자들로 펼침 const arr1 = [1, 2, 3, 4, 5]; console.log(arr1);// [1, 2, 3, 4, 5] // console.log(1, 2, 3, 4, 5); console.log(...arr1);// 1 2 3 4 5 ② concat보다 가독성있는 배열 결합 const arr1 = [1, 2, 3]; const arr2 = [4, 5, 6]; const arr3 = arr1.concat(arr2); const arr4 = [...arr1, ...arr2]; c..