전체 글
-
33_Symbol모던 자바스크립트 딥 다이브 독학 2023. 11. 30. 17:20
이름의 충돌 위험이 없는 유일한 프로퍼티 키를 만들기 위해 사용 심벌 값 생성 Symbol 함수 (new 연산자 X) const mySymbol = Symbol(); const mySymbol2 = Symbol('설명'); //심벌 값에 대한 설명으로 심벌 값 생성에 //어떠한 영향도 주지 않는다. 심벌 값은 문자열이나 숫자 타입으로 변환 X 불리언 타입으로는 암묵적으로 타입 변환 O Symbol.for / Symbol.keyFor 메서드 검색에 성공하면 새로운 심벌 값을 생성하지 않고 검색된 심벌 값을 반환 검색에 실패하면 새로운 심벌 값을 생성하여 Symbol.for 메서드의 인수로 전달된 키로 전역 심벌 레지스트리에 저장한 후, 생성된 심벌 값을 반환 심벌, 프로퍼티 키 객체의 프로퍼..
-
32_String모던 자바스크립트 딥 다이브 독학 2023. 11. 23. 16:48
String 생성자 함수 const strObj = new String(); const strObj2 = new String('Kim'); String 래퍼 객체는 배열과 유사하게 인덱스를 사용하여 각 문자에 접근할 수 있다.(유사 배열 객체이면서 이터러블) 단 문자열은 원시 값이므로 변경할 수 없다. new 연산자를 사용하지 않고 String 생성자 함수를 호출하면 String 인스턴스가 아닌 문자열을 반환한다.(명시적 타입 변환) length 프로퍼티 String 래퍼 객체는 배열과 마찬가지로 length 프로퍼티를 갖는다. String 메서드 원본 String 래퍼 객체를 직접 변경하는 메서드는 존재하지 않는다.(언제나 새로운 문자열 반환) String.prototype.indexOf..
-
31_RegExp모던 자바스크립트 딥 다이브 독학 2023. 11. 22. 10:01
정규 표현식 일정한 패턴을 가진 문자열의 집합을 표현하기 위해 사용하는 형식 언어 문자열을 대상으로 패턴 매칭 기능 제공 반복문과 조건문 없이 패턴을 정의, 테스트하지만 가독성이 좋지 않은 문제가 있다 정규 표현식 생성 const regexp = /is/i; // 패턴: is, 플래그: i(대소문자 구별하지 않고 검색) RegExp 생성자 함수 사용하여 RegExp 객체 생성 가능 new RegExp(pattern[, flags]) RegExp 메서드 RegExp.prototype.exec → 인수로 전달받은 문자열에 대해 정규 표현식 패턴 검색하여 매칭 결과를 배열로 반환. 매칭 결과 없는 경우 null 반환. g 플래그 지정해도 첫 매칭 결과만 반환 RegExp.prototype.test → 매칭 결..
-
30_Date모던 자바스크립트 딥 다이브 독학 2023. 11. 21. 08:07
빌트인 객체이면서 생성자 함수 UTC 국제 표준시가 기준 1970년 1월 1일 00:00:00(UTC) 기점 Date 생성자 함수 new Date() → 현재 날짜와 시간을 가지는 Date 객체를 반환 Date() → 날짜와 시간 정보를 나타내는 문자열 반환(객체를 반환하지 않는다) new Date(milliseconds) → 기점을 기준으로 인수로 전달된 밀리초만큼 경과한 날짜와 시간을 나타내는 Date 객체를 반환 new Date(dataString) → Date.parse 메서드에 의해 해석 가능한 형식의 문자열을 인수로 전달하면 지정된 날짜와 시간을 나타내는 Date 객체 반환 new Date(year, month[, day, hour, minute, second, millisecond]) → 연..
-
29_Math모던 자바스크립트 딥 다이브 독학 2023. 11. 19. 09:43
생성자 함수가 아니다. 정적 프로퍼티와 정적 메서드만 제공한다. Math 프로퍼티 Math.PI → 원주율 값을 반환 Math 메서드 Math.abs → 인수로 전달된 숫자의 절대값을 반환 Math.round → 인수로 전달된 숫자의 소수점 이하를 반올림한 정수를 반환 Math.round(1.4); // 1 Math.round(1.6); // 2 Math.round(-1.4); // -1 Math.round(-1.6); // -2 Math.ceil → 인수로 전달된 숫자의 소수점 이하를 올림한 정수를 반환 Math.ceil(1.4); // 2 Math.ceil(1.6); // 2 Math.ceil(-1.4); // -1 Math.ceil(-1.6); // -1 Math.floor → 인수로 전달된 숫자의..
-
28_Number모던 자바스크립트 딥 다이브 독학 2023. 11. 3. 10:27
원시 타입인 숫자를 다룰 때 유용한 프로퍼티와 메서드를 제공 Number 생성자 함수 const numObj = new Number(); console.log(numObj); // Number {[PrimitiveValue]: 0} const numObj2 = new Number(10); console.log(numObj2); // Number {[PrimitiveValue]: 10} //인수로 숫자가 아닌 값 전달하면 숫자로 강제 변환 const numObj3 = new Number('10'); console.log(numObj3); // Number {[PrimitiveValue]: 10} const numObj4 = new Number('hello'); console.l..
-
27_배열모던 자바스크립트 딥 다이브 독학 2023. 11. 1. 10:33
자바스크립트에 배열이라는 타입은 존재하지 않는다. 배열은 객체 타입이다. const arr = [1, 2, 3]; typeof arr; // object 배열의 생성 배열 리터럴 Array 생성자 함수 Array.of Array.from 일반 객체와 배열을 구분하는 차이는 값의 순서와 length 프로퍼티 자바스크립트 배열은 배열이 아니다 일반적인 배열의 동작을 흉내 낸 특수한 객체 배열의 요소를 위한 각각의 메모리 공간이 동일한 크기를 갖지 않아도 된다 연속적으로 이어져 있지 않을 수 있다 → 희소 배열 일반적인 배열과 자바스크립트 배열의 장단점 정리 일반적인 배열은 인덱스로 요소에 빠르게 접근 가능하지만 특정 요소를 검색하거나 삽입 또는 삭제 하는 경우에는 효율적이지 않다. 자바스크립트 배열은 해시 ..
-
26_ES6 함수의 추가 기능모던 자바스크립트 딥 다이브 독학 2023. 10. 29. 09:33
함수의 구분 일반 함수 메서드 화살표 함수 메서드 메서드 축약 표현으로 정의된 함수만을 의미한다. (인스턴스 생성 불가능) 화살표 함수 화살표 함수는 함수 선언문으로 정의할 수 없고 함수 표현식으로 정의해야 한다. 객체 리터럴을 반환하는 경우 객체 리터럴을 소괄호로 감싸 주어야 한다. const create = (id, content) => ({ id, content }); create(1, 'JavaScript'); // {id: 1, content: "JavaScript"} 함수 몸체가 여러 개의 문으로 구성된다면 함수 몸체를 감싸는 중괄호를 생략 불가능 즉시 실행 함수로 사용 가능 const person = (name => ({ sayHi() { return `Hi? My name i..