반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- next.config.mjs
- for in for of 차이점
- for of 문 예시
- setter 함수 동기적 실행
- for in 문 예시
- vue sass 사용하기
- input range 컬러변경
- vue scss 전역 설정
- 검색창 autofocus
- javascript cookie 설정
- forEach map 차이
- react input autofocus
- 접근자 함수
- 로지텍 MX Vertical 마우스
- react 검색 기능 구현
- 접근자 프로퍼티
- Object for in
- input range
- 객체 반복문
- javascript cookie 삭제
- 로컬스토리지 객체 저장
- 로컬스토리지 쓰기 읽기 삭제
- pip 명령 에러
- 로지텍 버티컬 마우스 사용 후기
- input type="range"
- vscode 재설치
- array method 요약
- vscode 초기화
- javascript cookie 얻기
- vue scss
Archives
- Today
- Total
짬짬이기록하기
var, let 차이점 본문
반응형
var는 function scope, 재선언 가능, 재할당 가능
let은 block scope, 재선언 불가능, 재할당 가능
function fn() {
var a = 1;
let b = 2;
console.log(a); // 1출력
console.log(b); // 2출력
//함수를 벗어나면 a,b둘다 메모리에서 해제됨
}
fn();
console.log(a); // ReferenceError발생
console.log(b); // ReferenceError발생
if(true) {
var a2 = 1;
let b2 = 2;
console.log(a2); // 1출력
console.log(b2); // 2출력
}
console.log(a2); // 1출력
console.log(b2); // ReferenceError발생
//a2는 function-scoped이기 때문에 function내부에 선언된게 아닐 경우 전역 변수로 hoisting됨
//b2는 block-scoped이기 때문에 if를 벗어나면 메모리에서 해제됨
반응형
'Web Development > Javascript' 카테고리의 다른 글
custom tag 만들기 (0) | 2023.04.07 |
---|---|
동기,비동기 기본 개념 (0) | 2022.09.04 |
event.stopPropagation (0) | 2020.07.30 |
selector 정리 (0) | 2020.07.30 |
유용한 jQuery Flipster Infinite Loop (0) | 2020.06.16 |