Skip to content

컴파일 단계에서 렉시컬 스코프의 지도가 생성되는 과정에서 발생할 수 있는 오류에는 어떤 것이 있나요? #63

Discussion options

You must be logged in to vote
답변

먼저 렉시컬 스코프의 지도는 JavaScript 엔진이 코드의 각 변수와 함수가 어디에서 선언되고, 어디에서 접근 가능한지를 나타내는 데이터 구조를 생성하는 것을 의미하고, 이과정은 코드가 실행되기전에 이루어짐

컴파일 단계에서 렉시컬 스코프의 지도가 생성될 때 발생할 수 있는 오류는 주로 변수의 선언과 사용과 관련이 있습니다.

  1. 변수 재선언 오류: 같은 스코프 내에서 같은 이름의 변수를 다시 선언하려 할때 발생
let x = 10;
let x = 20; // SyntaxError: Identifier 'x' has already been declared

2.변수 참조 오류(ReferenceError): 변수가 초기화되기 전에 접근하려고 할 때 발생합니다. 이는 Temporal Dead Zone (TDZ)에 의해 보호되는 let과 const에 대해 자주 발생합니다.

console.log(x); // ReferenceError: Cannot access 'x' before initialization
let x = 10;
  1. 블록 스코프 변수 참조 오류: 블록 스코프 내 변수를 밖에서 접근하려 할 때 발생
if (true) {
  let y = 10;
}
console.log(y); // ReferenceError: y is not defined
  1. 사용하지 않는 변수 경고: 변수가 선언되었지만 사용되지 않을 때 발생…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by wogus216
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants