TIL23: Lexical Scope

Charlie·2020년 9월 20일
0

Pre Course TIL

목록 보기
23/45
post-thumbnail
let age = 27;
let name = 'charlie';
let height = 179;

function outerFn() {
  let age = 24;
  name = 'tommy';
  let height = 178;
  
  function innerFn() {
    age = 26;
    let name = 'mike';
    return height;
  }
  innerFn();
  
  return innerFn;
}
const innerFn = outerFn();
innerFn(); // ?

코드의 마지막 부분에 위치하고 있는 innerFn 함수는 outerFn 함수의 실행 결과 생성, 반환된 함수로써 생성될 당시의 Lexical Scope가 현재 코드의 위치상 Scope와 다릅니다.

코드 출처: 코드스테이츠(CodeStates)

0개의 댓글