undefined 방지하기
·
JavaScript
자바스크립트는 값이 할당되지 않은 변수에게는 undefined라는 값을 할당한다. 값이 할당되어 있기에 코드가 동작할 때도 있지만, undefined때문에 그 변수를 건드리려고 해도 건드리지 못한다. https://github.com/tc39/proposal-nullish-coalescing GitHub - tc39/proposal-nullish-coalescing: Nullish coalescing proposal x ?? y Nullish coalescing proposal x ?? y. Contribute to tc39/proposal-nullish-coalescing development by creating an account on GitHub. github.com 객체에서 이런 경우가 종종 발..
JavaScipt 배열에서 중복 개수 구하기
·
JavaScript
ForEach 사용하기 arr.forEach((x) => { result[x] = (result[x] || 0)+1; }); 풀어쓴 것 if(result[x]){ result[x]+=1 } else{ result[x]=1 } Object로 만들기 function findSingle(arr){ return arr.reduce((pv, cv)=>{ pv[cv] = (pv[cv] || 0) + 1; return pv; }, {});
JS replace
·
JavaScript
var newStr = str.replace(regexp|substr, newSubstr|function) 특수 교체 $$ "$" 기호를 삽입합니다. $& 매치된 문자열을 삽입합니다. $` 매치된 문자열 앞쪽까지의 문자열을 삽입합니다. $' 매치된 문자열 이후의 문자열을 삽입합니다. $n *n*이 1이상 99이하의 정수라면, 첫번째 매개변수로 넘겨진 RegExp객체에서 소괄호로 묶인 *n*번째의 부분 표현식으로 매치된 문자열을 삽입합니다. 매개변수가 function 일때 이 경우, 함수는 정규표현식 매치가 수행된 후 호출될 것이고, 함수의 반환값은 교체될 문자열이 된다. 만약 정규표현식의 플래그로 글로벌(g)이 오는 경우, 함수는 매치될 때마다 계속 호출됨. function replacer(match, ..
정렬
·
JavaScript
https://youtu.be/kPRA0W1kECg https://www.bigocheatsheet.com/ Big-O Algorithm Complexity Cheat Sheet (Know Thy Complexities!) @ericdrowell Know Thy Complexities! Hi there! This webpage covers the space and time Big-O complexities of common algorithms used in Computer Science. When preparing for technical interviews in the past, I found myself spending hours crawling the internet putting t www.big..
Babel과 Webpack을 이용한 개발 환경 구축
·
JavaScript
Babel 설치후 Babel 프리셋 설치, babel.config.json 설정 파일 작성을 해줘야한다 @babel/preset-env -> Babel 프리셋 프리셋 설치 후 babel.config.json 설정파일을 생성하고 아래처럼 적어준다 { "presets": ["@babel/preset-env"] } Browserslist https://blog.shiren.dev/2020-12-01/ 브라우저를 선택하는 옵션 기능만 따로 뽑아 놓은 도구 트랜스파일링 하나의 프로그래밍 언어를 다른 언어로 컴파일하는 특별한 형태 package.json안에 script에 이 명령어 추가 "bulid": "babel src/js -w -d dist/js" -w : 타깃 폴더에 있는 모든 자바스크립트 파일들의 변경을 ..
JavaScript $
·
JavaScript
const $button=docu~ const $elem=docu~ 변수 앞에 $이게 붙어있는 경우를 종종 볼 수 있고 jQuery가 아니여서 뭔지 찾아봤다 https://www.thoughtco.com/and-in-javascript-2037515 What's In a Name? Understanding $ and _ in JavaScript The $ and _ characters in JavaScript are identifiers that are considered to be letters rather than special characters. www.thoughtco.com _(언더바)는 private를 나타낼때 쓰는 식별자이고 $도 마찬가지로 식별자다 $은 document.getElement..