[1주차][동동] 호이스팅이란?#96
Open
bigsaigon333 wants to merge 1 commit into
Open
Conversation
jordan-choi
reviewed
Oct 26, 2021
Collaborator
jordan-choi
left a comment
There was a problem hiding this comment.
보충하면 좋을 부분에 대해 간단한 코멘트 남겼습니다. 잘 읽었습니다. 감사합니다.
|
|
||
| ## 결론 | ||
|
|
||
| - 호이스팅이란 var로 변수를 선언하면 선언한 위치와 상관없이 함수의 최상단으로 변수의 선언이 끌어올려지는 현상입니다. |
Collaborator
There was a problem hiding this comment.
"var로 변수를 선언하면" -- var 변수만 호이스팅되는 게 아니기 때문에 var는 빼야할 것 같습니다. (후에 예시로 드는 것이 어떨까요?)
Contributor
Author
There was a problem hiding this comment.
저는 let과 const로 선언한 변수는 끌어올려지더라도 접근이 불가능하기 때문에 굳이 호이스팅된다고 말할 필요가 없다고 생각했는데, 엄밀히 말하면 함수 호출 직후 식별자 정보를 모두 수집하기 때문에 var 키워드는 제외하는게 좋겠네요!
좋은 피드백 감사합니다!
|
|
||
| - 만약 var로 선언한 변수가 함수 바깥에 선언되어 있다면 전역 스코프의 최상단으로 변수선언이 끌어올려집니다. | ||
|
|
||
| - 호이스팅이 일어나더라도 변수의 선언만 함수의 맨 위로 끌어올려질 뿐, 값의 할당은 끌어올려지지 않습니다. 호이스팅이 일어난 변수에 값의 할당이 이뤄지기 전에 접근하면, 변수는 undefined 값을 가지고 있습니다. |
Collaborator
There was a problem hiding this comment.
변수는 선언부와 할당부를 나누어 선언부만 위로 끌어올려지는 반면, 함수 선언(function f(){})은 함수 전체가 끌어올려집니다.
|
|
||
| - let, const | ||
|
|
||
| - 호이스팅이 발생하는 JS 엔진내의 구체적인 메커니즘(`lexical Environment`) |
Contributor
Author
There was a problem hiding this comment.
lexical environment 를 쉽게 설명할 자신이 없네요 😭
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#95