호이스팅
-
호이스팅, 호이스팅 원인, 호이스팅 종류CS지식 2023. 11. 5. 14:30
첫 콘솔을 보면 var는 undefined가 찍힌다. 이처럼 선언 라인 전에도 변수를 참조할 수 있는 현상을 '호이스팅' 이라고 한다. var 키워드는 선언과 함께 undefined로 초기화되어 메모리에 공간을 확보한다. let과 const 키워드는 선언만 되고 초기화되지 않은 상태로 선언만 환경레코드(메모리)에 등록된다. (선언 라인에 도달하기 전에는 메모리에 공간을 확보하지 못한다.) 자바스크립트의 모든 선언에는 호이스팅이 일어나지만 let, const를 이용한 선언문을 호이스팅이 발생하지 않는 것처럼 동작한다. let, const 키워드로 선언된 변수를 선언문 이전에 참조하면 참조 에러(ReferenceError)가 발생하는데 이는 let과 const에도 호이스팅이 일어나기 때문에 에러를 일으키는 ..
-
실행컨텍스트, 호이스팅, 스코프체이닝 (feat. 테코톡 하루님)CS지식 2023. 11. 4. 15:29
실행컨텍스트, 호이스팅, 스코프체이닝을 완벽하게 이해하고 싶은데 호이스팅, 생성 단계, 실행 단계, 선언, 초기화, 일시적 사각지대, 함수 표현식, 함수 선언문, 식별자 결정, 스코프 체인, 스코프 체이닝 등의 여러 개념들이 얽혀있어서 정리가 잘 안됐다. 그런데 테코톡에서 하루님께서 실행컨텍스트를 발표해주신 영상을 보고 속이 시원할정도로 이해가 쏙쏙 잘됐다. 너무 감사했다..ㅠㅠ 그래서 이 영상을 보며 개념을 정리해보았다! https://youtu.be/EWfujNzSUmw?si=ICfUnYVPczB2HqTh 실행컨텍스트에는 Record가 있고 Outer가 있다. 이를 먼저 이해하면 최종적으로 실행컨텍스트를 더욱 이해할 수 있다! 1. Record로 JS 호이스팅 이해하기 이처럼 첫 콘솔을 보면 unde..