목록개발/JavaScript (19)
게으른개발너D
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/lx7Zq/btsnkL1KxOi/tW6dvO0UlW471YWBLz9h41/img.jpg)
Array prototype 1. Array.prototype.copyWithin( ) 배열의 일부를 얕게 복사한 뒤, 동일한 배열의 다른 위치에 덮어쓰고 그 배열을 반환한다. 이 때, 크기(배열의 길이)를 수정하지 않고 반환한다. array.copyWithin(target, start, end); index target 자리에 array의 index start에서 end 전까지의 element를 복사해서 넣음 array.copyWithin(target, start); index target 자리에 array의 index start에서 끝까지의 element를 복사해서 넣음 [1, 2, 3, 4, 5].copyWithin(-2); // [1, 2, 3, 1, 2] [1, 2, 3, 4, 5].copyWi..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/sc63W/btsnj8JznQR/tBJAvzliinKeddr2K6MdY1/img.jpg)
String prototypes 1. String.prototype.charCodeAt( ) 주어진 인덱스에 대한 UTF-16 코드를 나타내는 0부터 65535 사이의 정수를 반환 const sentence = "Hi"; // "문자열".charCodeAt(문자열 자릿수); const char = sentence.charCodeAt(0); // "Hi"에서 0번째 index인 'H'를 번호로 변환 console.log(char); // 72 cf) String.fromCharCode() - 아스키코드표 번호 코드 번호 코드 번호 코드 33 ! 64 @ 95 _ 34 " 65 A 96 ` 35 # 66 B 97 a 36 $ 67 C 98 b 37 % 68 D 99 c 38 & 69 E 100 d 39 ' ..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/ciUPcl/btsnoEmSeZv/OP6cKB1ZKzofrrqTTllOh1/img.jpg)
Object Setting the Initial Value const arr = ["a", "b", "a", "a", "b", "c", "a", "b"]; const obj = {}; for(const a of arr) { if(obj[a] === undefined) { obj[a] = 1; } else { obj[a] += 1; } } console.log(obj) // { "a": 4, "b": 3, "c": 1 } 이렇게 할 수도 있지만 논리 연산자 || 를 이용하여 한 줄로 작성할 수도 있음 const arr = ["a", "b", "a", "a", "b", "c", "a", "b"]; const obj = {}; for(const a of arr) { obj[a] = (obj[a] || 0) +..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/148Wd/btsnn7bRMtp/PK8WPqZhOKcTLrhXKkkj00/img.jpg)
Math Method 1. Math.sqrt( ) 숫자의 제곱근 반환 Math.sqrt(4) // 2 Math.sqrt(2) // 1.414213562373095 Math.sqrt(0) // 0 Math.sqrt(-3) // NaN 2. Math.random( ) 0 이상 1 미만의 구간에서 랜덤 수 생성 // 3이상 64이하의 랜덤 숫자 생성 const min = 3; const max = 64; const num = Math.floor(Math.random() * (max - min + 1) + min); 3. Math.trunc( ) 주어진 값의 소수부분을 제거하고 숫자의 정수부분을 반환. Math.floor()를 쓸 수도 있지만 숫자가 마이너스 값일 경우 소수부분을 제거한 값과 다른 값이 나오기때..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/etFajA/btsni9heW46/3CKSQ0y3kU7cKeUVkEX5T1/img.jpg)
Number Prototypes 1. Number.prototype.toString() 10진수를 n진수로 변환 const num = 5; // 5를 2진수로 변환 const change1 = num.toString(2); console.log(change1); // output:{string} "101" // 5를 4진수로 변환 const change2 = num.toString(4); console.log(change2); // output:{string} "11" 반대) (Built-in Objects) parseInt() [Built-in Objects] 까먹는 것 정리 Built-in Objects (표준내장객체) 1. parseInt() n진수를 10진수로 변환 (문자열 인자를 파싱하여 특정 ..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/czNtS4/btsnnNdBJzX/Pp1cQFP0vgMu159RxA26tK/img.jpg)
Built-in Objects (표준내장객체) 1. parseInt() n진수를 10진수로 변환 (문자열 인자를 파싱하여 특정 진수의 정수를 반환) const numStr = '101'; // 2진수 '101'을 10진수로 변환 const change1 = parseInt(numStr, 2); console.log(change1); // output:{number} 5 // 5진수 '101'을 10진수로 변환 const change2 = parseInt(numStr, 5); console.log(change2); // output:{number} 26 반대) Number.prototype.toString() [Number] 까먹는 것 정리 Number Prototypes 1. Number.prototyp..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/sk9hw/btsp1lddb0u/D1AkH7pKXgPAtboC5I0tn1/img.jpg)
✨ What are Classes ✨ classes는 화려한 object이다. class는 보통 많은 사람들이 라이브러리나 리액트 같은 것을 만들 때 classes를 export한 다음에 classes를 이용한다. 우리가 엄청 많은 코드를 가지고 있고, 이걸 구조화하길 원할 때, class를 이용하면 매우 유용하다. 왜냐하면 class를 재사용할 수 있기 때문이다. class는 기본적으로 blueprint(청사진)이며 화려한 object이다. User라는 class를 만들어 보자 class는 안에 constructor라는 걸 가지고 있는데, constructor는 class를 말그대로 construct(구성)한다는 constructor이다. class User { constructor() { this.u..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/kPvgw/btspOCnz2AS/GcuOkrpTDXfgW5cf7yQYW0/img.jpg)
✨ Async Await ✨ https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/async_function async function - JavaScript | MDN async function 선언은 AsyncFunction객체를 반환하는 하나의 비동기 함수를 정의합니다. 비동기 함수는 이벤트 루프를 통해 비동기적으로 작동하는 함수로, 암시적으로 Promise를 사용하여 결과를 반환 developer.mozilla.org async, await는 두 Promise의 업데이트이다. async, await를 만든 이유는 보기 좋은 코드를 만들기 위해서이다. then이나 catch같은 것들은 구식이다. 많은 then을 사용해야 ..