이봐, 난 자바 스크립트 클로저를 이해하고이 코드 조각에 빠른 질문을하기 위해 노력하고있어 모든자바 스크립트 클로저와 내부 범위
var a = 5;
function woot() {
console.log('a == 5 woot: ' + (a == 5).toString());
var a = 6;
function test() {
console.log('a == 6 test: ' + (a == 6).toString());
}
test();
}
console.log('a == 5 outside: ' + (a == 5).toString());
woot();
console.log('a == 5 end: ' + (a == 5).toString());
출력 : 내가
a == 5 outside: true
a == 5 woot: false
a == 6 test: true
a == 5 end: true
를 기다리고 있었다 모든 출력은 true
이지만 a
은 의 첫 번째 줄에 undefined
입니다. 왜 이런거야?