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 |
Tags
- Navigation Bar
- jsx
- JS
- slick
- 파이썬
- 호이스팅
- baekjoon
- programmers
- 알고리즘
- JavaScript
- 취준생
- 게임 맵 최단거리
- react-slick
- react slick
- navbar
- 18352
- 프로그래머스
- var
- Python
- let
- Carousel
- 함수선언식
- 함수표현식
- 레지스터
- Reactjs
- swea
- 취뽀기원
- react
- HTML
- 코딩테스트
Archives
- Today
- Total
고짬기록
호이스팅 / var, let, const / 함수 선언식, 함수 표현식 본문
호이스팅
- 위로 끌어올려지는 것 같은 현상
- var 변수 선언과 함수 선언문에서 발생
var, let, const
var | let | const | |
중복 선언 | 가능 | 불가능 | 불가능 |
재할당 | 가능 | 가능 | 불가능 |
스코프 레벨 | 함수 스코프 | 블록 스코프 | 블록 스코프 |
1. 중복 선언
2. 재할당
3. 스코프 레벨
function temp() {
if(true) {
var a = 1;
console.log(a) // 1
}
console.log(a) // 1 -> 함수스코프
}
temp()
console.log(a) // ReferenceError: a is not defined -> 함수 밖이므로
function temp() {
if(true) {
let a = 1;
console.log(a) // 1 -> 블록 스코프
}
console.log(a) // ReferenceError: a is not defined -> 블록 밖이므로
}
temp()
console.log(a) // ReferenceError: a is not defined
⭐호이스팅⭐
console.log(n) // undefined
var n = 'merong';
console.log(m) // Uncaught ReferenceError: m is not defined
let m = 'no-merong';
console.log(l) // Uncaught ReferenceError: l is not defined
const l = 'HeHe';
함수 선언식 vs 함수 표현식
함수 선언식
function sum(a, b) {
return a + b;
};
함수 표현식
const minus = function(a, b) {
return a - b;
};
⭐호이스팅⭐
// 함수 선언식
console.log(sum(2, 3)) // 5
function sum(a, b) {
return a + b;
};
// 함수 표현식
console.log(minus(5, 2)) // Uncaught TypeError: minus is not a function
var minus = function(a, b) {
return a - b;
};
Comments