let x = 0; // 1. declaring that the x is 0
function first(){
x=1; // 3. x is now 1
function second(){
x = 2; // 5. x is now 2
function third(){
x = 3; // 6. now x is 3, but from my knowledge, x should only be 3 when called inside this last function.
// console.log(x) <- like this here
}
third() // 6. calling third() function
}
second() // 4. calling second() function
}
first(); // 2. calling the first() function
console.log(x) // Why the result is 3 instead of 0?
분명 지역변수에서 재선언해준건데 우째서
바깥에서 불렀을때는 지역변수, 심지어 제일 마지막 함수에서 설정한 지역변수가 x로 설정되나욤?
이거 어디서 본거같긴한데
참조와 메모리할당인가 그거인가?
댓글 0