프론트엔드/자바스크립트
호출스택과 스코프체인
호재이
2023. 3. 15. 17:05
const x = 'x'
function c(){
const y = 'y'
console.log('c')
function b(){
const z = 'z'
console.log('b')
c()
}
}
function a(){
const x = 'x'
console.log('a')
b();
}
a()
c()
스코프체인 :
함수에서 어떤값에 접근이 가능한지를 알아내는것이다.
스코프 체인은 함수의 선언만 보면 됩니다
const x = 'x'
function c(){
const y = 'y'
console.log('c')
function b(){
const z = 'z'
console.log('b')
c()
}
}
function a() {
const x = 'x'
console.log('a')
b()
}
// 호출
a() // 결과 b is not defined
b()