5. 실행 컨텍스트와 클로저 #1 실행 컨텍스트 개념

2021. 11. 5. 15:41JavaScript/basic

이전글

https://yonghwankim-dev.tistory.com/159

 

4. 함수와 프로토타입 체이닝 #5 프로토타입 체이닝

이전글 https://yonghwankim-dev.tistory.com/158 4. 함수와 프로토타입 체이닝 #4 함수 호출과 this 이전글 https://yonghwankim-dev.tistory.com/70?category=962746 4. 함수와 프로토타입 체이닝 #3 함수의 다..

yonghwankim-dev.tistory.com

 

본 글은 INSIDE JAVASCRIPT 도서의 내용을 복습하기 위해 작성된 글입니다.

 

5장 목차

  1. 실행 컨텍스트(Execution context)의 개념
  2. 활성 객체(Activation object)와 변수 객체(Variable object)
  3. 스코프 체인(Scope chain)
  4. 클로저(closure)

요약 및 정리

실행 컨텍스트(Execution Context)

  • 실행 가능한 자바스크립트 코드 블록이 실행되는 환경

실행 컨텍스트가 형성되는 경우

  • 전역 코드
  • eval() 함수로 실행되는 코드
  • 함수 실행

실행 컨텍스트의 생성

  • 현재 실행되는 컨텍스트에서 이 컨텍스트와 관련 없는 실행 코드(대개 다른 함수)가 실행되면, 새로운 컨텍스트가 생성되어 스택에 들어가고 제어권이 그 컨텍스트로 이동함

실행 컨텍스트 예제

console.log("This is global context");

function ExContext1(){
    console.log("This is ExContext1");
}

function ExContext2(){
    ExContext1();
    console.log("This is ExContext2");
}

ExContext2();

// Expected Output
// This is global context
// This is ExContext1
// This is ExContext2

 

References

source code : https://github.com/yonghwankim-dev/javascript_study
INSIDE JAVASCRIPT 한빛미디어, 송형주 저