var : 함수 레벨의 유효범위
let, const : 블록 레벨의 유효범위 가짐
Truthy : true, {}, [], 2, 'false', '2'
Falsy : false, '', null, undefined, 0, -0. NaN
- 즉시실행함수
IIFE (Immediately-Invoked Function Expression)
// IIFE 방법 1
(function () {
console.log(a + 2)
}) ();
// IIFE 방법 2
(function () {
console.log(a + 2)
} ());
- 호이스팅 (Hoisting)
함수 선언부가 유효범위 최상단으로 끌어올려지는 현상
const x = 5
plus()
function plus() {
console.log(x + 3)
}
🔵 타이머 함수
setTimeout(함수, 시간) // 일정 시간 후 함수 실행
setInterval(함수, 시간) // 시간 간격마다 함수 실행
clearTimeout() // 설정된 Timeout 함수 종료
clearInterval() // 설정된 Interval 함수 종료
- 일반 함수는 호출 위치에 따라 this 정의됨
- 화살표 함수는 자신이 선언된 함수 범위에서 this 정의
🔵 전개 연산자 Spread
const names = ['Bob', 'James', 'Sam']
console.log(...names)
// console.log('Bob', 'James', 'Sam') 와 같은 결과 나옴
매개변수에서 사용할 경우 - 나머지를 모두 받는 경우로 사용 rest parameter
- 참조형 데이터(Object, Array, Function)는 불변성이 없음
- 깊은 복사 (Deep copy)
lodash의 cloneDeep 활용하기
Lodash
_.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 });_.partition([1, 2, 3, 4], n => n % 2);DownloadLodash is released under the MIT license & supports modern environments. Review the build differences & pick one that’s right for you.InstallationIn
lodash.com
- json
하나의 문자 데이터
(json화 시키려면 JSON.stringify(aaa))
undefined 사용X
'Web > HTML CSS JS' 카테고리의 다른 글
| [SCSS] 기초 정리 / Sass (0) | 2022.10.11 |
|---|---|
| [JS] 정규표현식 RegExp / 정규식 (0) | 2022.10.04 |
| [JS] local storage / Query String (0) | 2022.10.04 |
| [HTML / CSS] 기초 정리 (0) | 2022.09.29 |